Skip to content

Commit 81dcdd2

Browse files
committed
update for h5py NULL_SPACE feature - cf h5py issue #279
1 parent 3a6acc6 commit 81dcdd2

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

h5json/hdf5db.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,10 @@ def getNullRegionReference(self):
814814

815815
def getShapeItemByDsetObj(self, obj):
816816
item = {}
817-
if len(obj.shape) == 0:
817+
if obj.shape is None:
818+
# new with h5py 2.6, null space datasets will return None for shape
819+
item['class'] = 'H5S_NULL'
820+
elif len(obj.shape) == 0:
818821
# check to see if this is a null space vs a scalar dataset we'll do
819822
# this by seeing if an exception is raised when reading the dataset
820823
# h5py issue https://github.com/h5py/h5py/issues/279 will provide a
@@ -846,7 +849,7 @@ def getShapeItemByDsetObj(self, obj):
846849

847850
def getShapeItemByAttrObj(self, obj):
848851
item = {}
849-
if obj.get_storage_size() == 0:
852+
if obj.shape is None or obj.get_storage_size() == 0:
850853
# If storage size is 0, assume this is a null space obj
851854
# See: h5py issue https://github.com/h5py/h5py/issues/279
852855
item['class'] = 'H5S_NULL'
@@ -2100,6 +2103,10 @@ def getDatasetValuesByUuid(self, obj_uuid, slices=Ellipsis, format="json"):
21002103
self.log.info(msg)
21012104
raise IOError(errno.EINVAL, msg)
21022105

2106+
if dset.shape is None:
2107+
# null space dataset (with h5py 2.6.0)
2108+
return None
2109+
21032110
rank = len(dset.shape)
21042111

21052112
if rank == 0:

test/unit/hdf5dbTest.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,37 @@ def testCreateCommittedCompoundTypeDataset(self):
507507

508508

509509
def testReadZeroDimDataset(self):
510-
filepath = getFile('zerodim.h5', 'readzerodeimdataset.h5')
511-
d111_values = None
512-
d112_values = None
513-
with Hdf5db(filepath, app_logger=self.log) as db:
510+
filepath = getFile('zerodim.h5', 'readzerodeimdataset.h5')
511+
512+
with Hdf5db(filepath, app_logger=self.log) as db:
514513
dsetUuid = db.getUUIDByPath('/dset')
515514
self.assertEqual(len(dsetUuid), UUID_LEN)
516515
dset_value = db.getDatasetValuesByUuid(dsetUuid)
517516
self.assertEqual(dset_value, 42)
517+
518+
519+
def testReadNullSpaceDataset(self):
520+
filepath = getFile('null_space_dset.h5', 'readnullspacedataset.h5')
521+
522+
with Hdf5db(filepath, app_logger=self.log) as db:
523+
dsetUuid = db.getUUIDByPath('/DS1')
524+
self.assertEqual(len(dsetUuid), UUID_LEN)
525+
obj = db.getDatasetObjByUuid(dsetUuid)
526+
shape_item = db.getShapeItemByDsetObj(obj)
527+
self.assertTrue('class' in shape_item)
528+
self.assertEqual(shape_item['class'], 'H5S_NULL')
529+
530+
def testReadNullSpaceAttribute(self):
531+
filepath = getFile('null_space_attr.h5', 'readnullspaceattr.h5')
532+
533+
with Hdf5db(filepath, app_logger=self.log) as db:
534+
rootUuid = db.getUUIDByPath('/')
535+
self.assertEqual(len(rootUuid), UUID_LEN)
536+
item = db.getAttributeItem("groups", rootUuid, "attr1")
537+
self.assertTrue('shape' in item)
538+
shape_item = item['shape']
539+
self.assertTrue('class' in shape_item)
540+
self.assertEqual(shape_item['class'], 'H5S_NULL')
518541

519542
def testReadAttribute(self):
520543
# getAttributeItemByUuid

0 commit comments

Comments
 (0)