Skip to content

Commit

Permalink
Merge pull request #1625 from dota17/issue#1540
Browse files Browse the repository at this point in the history
Fix creating attribute with Empty
  • Loading branch information
takluyver committed Aug 7, 2020
2 parents bb1dee4 + 477c39b commit 6f4c578
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion h5py/_hl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class Empty(object):
size = None

def __init__(self, dtype):
self.dtype = dtype
self.dtype = np.dtype(dtype)

def __eq__(self, other):
if isinstance(other, Empty) and self.dtype == other.dtype:
Expand Down
9 changes: 9 additions & 0 deletions h5py/tests/test_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def test_named(self):
self.assertEqual(htype, htype2)
self.assertTrue(htype.committed())

def test_empty(self):
# https://github.com/h5py/h5py/issues/1540
""" Create attribute with h5py.Empty value
"""
self.f.attrs.create('empty', h5py.Empty('f'))
self.assertEqual(self.f.attrs['empty'], h5py.Empty('f'))

self.f.attrs.create('empty', h5py.Empty(None))
self.assertEqual(self.f.attrs['empty'], h5py.Empty(None))

class TestMutableMapping(BaseAttrs):
'''Tests if the registration of AttributeManager as a MutableMapping
Expand Down
29 changes: 29 additions & 0 deletions news/empty-constructor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
New features
------------

* <news item>

Deprecations
------------

* <news item>

Exposing HDF5 functions
-----------------------

* <news item>

Bug fixes
---------

* Fix creating attribute with Empty by converting its dtype to a numpy dtype.

Building h5py
-------------

* <news item>

Development
-----------

* <news item>

0 comments on commit 6f4c578

Please sign in to comment.