Skip to content

Commit b904ea5

Browse files
committed
fix for datasets with fillvalue
1 parent 29ae237 commit b904ea5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/h5json/hdf5db.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ def getDatasetValues(self, dset_id, sel):
570570

571571
dtype = self.getDtype(dset_json)
572572

573+
if "creationProperties" in dset_json:
574+
cpl = dset_json["creationProperties"]
575+
else:
576+
cpl = {}
577+
573578
# determine if we need to make a read request or not
574579
if dset_id in self._new_objects:
575580
fetch = False
@@ -587,7 +592,13 @@ def getDatasetValues(self, dset_id, sel):
587592
if fetch:
588593
arr = self.reader.getDatasetValues(dset_id, sel, dtype=dtype)
589594
else:
590-
arr = np.zeros(sel.mshape, dtype=dtype)
595+
if "fillValue" in cpl:
596+
fillValue = cpl["fillValue"]
597+
# TBD: fix for compound types
598+
arr = np.zeros(sel.mshape, dtype=dtype)
599+
arr[...] = fillValue
600+
else:
601+
arr = np.zeros(sel.mshape, dtype=dtype)
591602

592603
if "updates" in dset_json:
593604
# apply any non-flushed changes that intersect the current selection

test/unit/hdf5db_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,24 @@ def testResizableDataset(self):
526526

527527
db.close()
528528

529+
def testFillValueDataset(self):
530+
dtype = np.uint32
531+
db = Hdf5db(app_logger=self.log)
532+
root_id = db.open()
533+
cpl = {"fillValue": 0xdeadbeef}
534+
dset_id = db.createDataset((), dtype=dtype, cpl=cpl)
535+
db.createHardLink(root_id, "dset", dset_id)
536+
dset_json = db.getObjectById(dset_id)
537+
self.assertTrue("creationProperties" in dset_json)
538+
cpl = dset_json["creationProperties"]
539+
self.assertTrue("fillValue" in cpl)
540+
self.assertEqual(cpl["fillValue"], 0xdeadbeef)
541+
sel_all = selections.select((), ...)
542+
arr = db.getDatasetValues(dset_id, sel_all)
543+
self.assertEqual(arr.dtype, dtype)
544+
self.assertEqual(arr.shape, ())
545+
self.assertEqual(arr[()], 0xdeadbeef)
546+
529547

530548
if __name__ == "__main__":
531549
# setup test files

0 commit comments

Comments
 (0)