Skip to content

Commit 5044d80

Browse files
committed
fixed bug with scalar dataset with array type
1 parent 7c8f802 commit 5044d80

File tree

6 files changed

+77
-2
lines changed

6 files changed

+77
-2
lines changed

data/hdf5/scalar_array_dset.h5

7.06 KB
Binary file not shown.

data/json/scalar_array_dset.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"apiVersion": "1.1.0",
3+
"datasets": {
4+
"8752a454-05e2-11e7-900a-3c15c2da029e": {
5+
"alias": [
6+
"/DS1"
7+
],
8+
"creationProperties": {
9+
"allocTime": "H5D_ALLOC_TIME_LATE",
10+
"fillTime": "H5D_FILL_TIME_IFSET",
11+
"layout": {
12+
"class": "H5D_CONTIGUOUS"
13+
}
14+
},
15+
"shape": {
16+
"class": "H5S_SCALAR"
17+
},
18+
"type": {
19+
"base": {
20+
"base": "H5T_IEEE_F32LE",
21+
"class": "H5T_FLOAT"
22+
},
23+
"class": "H5T_ARRAY",
24+
"dims": [
25+
3,
26+
2
27+
]
28+
},
29+
"value": [
30+
[
31+
0.0,
32+
0.0
33+
],
34+
[
35+
0.0,
36+
0.0
37+
],
38+
[
39+
0.0,
40+
0.0
41+
]
42+
]
43+
}
44+
},
45+
"groups": {
46+
"8750b178-05e2-11e7-b6e4-3c15c2da029e": {
47+
"alias": [
48+
"/"
49+
],
50+
"links": [
51+
{
52+
"class": "H5L_TYPE_HARD",
53+
"collection": "datasets",
54+
"id": "8752a454-05e2-11e7-900a-3c15c2da029e",
55+
"title": "DS1"
56+
}
57+
]
58+
}
59+
},
60+
"root": "8750b178-05e2-11e7-b6e4-3c15c2da029e"
61+
}

h5json/hdf5db.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,10 @@ def getShapeItemByDsetObj(self, obj):
822822
# this by seeing if an exception is raised when reading the dataset
823823
# h5py issue https://github.com/h5py/h5py/issues/279 will provide a
824824
# better way to determine null spaces
825+
# Update 3/10/17: Above issue is closed, but waiting on 2.7 final release
825826
try:
826827
val = obj[...]
827-
if not val:
828+
if val is None:
828829
self.log.warning("no value returned for scalar dataset")
829830
item['class'] = 'H5S_SCALAR'
830831
except IOError:
@@ -2118,7 +2119,7 @@ def getDatasetValuesByUuid(self, obj_uuid, slices=Ellipsis, format="json"):
21182119
except IOError:
21192120
# assume null dataspace, return none
21202121
return None
2121-
if not val:
2122+
if val is None:
21222123
self.log.warning("no value returned from scalar dataset")
21232124

21242125
if type(slices) != list and type(slices) != tuple and slices is not Ellipsis:

test/integ/h5tojson_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"resizable.h5",
8383
"sample.h5",
8484
"scalar.h5",
85+
"scalar_array_dset.h5",
8586
"scalar_attr.h5",
8687
"tall.h5",
8788
"tall_with_udlink.h5",

test/integ/jsontoh5_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
# "sample.json",
7777
"scalar.json",
7878
#"scalar_attr.json",
79+
#"scalar_array_dset.json",
7980
"tall.json",
8081
"tall_with_udlink.json",
8182
"tgroup.json",

test/unit/hdf5dbTest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,17 @@ def testReadNullSpaceDataset(self):
526526
shape_item = db.getShapeItemByDsetObj(obj)
527527
self.assertTrue('class' in shape_item)
528528
self.assertEqual(shape_item['class'], 'H5S_NULL')
529+
530+
def testReadScalarSpaceArrayDataset(self):
531+
filepath = getFile('scalar_array_dset.h5', 'readscalarspacearraydataset.h5')
532+
533+
with Hdf5db(filepath, app_logger=self.log) as db:
534+
dsetUuid = db.getUUIDByPath('/DS1')
535+
self.assertEqual(len(dsetUuid), UUID_LEN)
536+
obj = db.getDatasetObjByUuid(dsetUuid)
537+
shape_item = db.getShapeItemByDsetObj(obj)
538+
self.assertTrue('class' in shape_item)
539+
self.assertEqual(shape_item['class'], 'H5S_SCALAR')
529540

530541
def testReadNullSpaceAttribute(self):
531542
filepath = getFile('null_space_attr.h5', 'readnullspaceattr.h5')

0 commit comments

Comments
 (0)