Skip to content

Commit acfd41a

Browse files
committed
fix bug with one element selection puts (of compound type)
1 parent 0736df6 commit acfd41a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

h5json/hdf5db.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,6 +2228,7 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
22282228
dt = dset.dtype
22292229
typeItem = getTypeItem(dt)
22302230
itemSize = getItemSize(typeItem)
2231+
22312232
if itemSize == "H5T_VARIABLE" and format == "binary":
22322233
msg = "Only JSON is supported for for this data type"
22332234
self.log.info(msg)
@@ -2262,8 +2263,13 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
22622263
arr = np.fromstring(data, dtype=dset.dtype)
22632264
arr.reshape(dset.shape)
22642265
dset[()] = arr
2265-
else:
2266-
dset[()] = data
2266+
else:
2267+
# json data
2268+
try:
2269+
dset[()] = data
2270+
except TypeError as te:
2271+
raise IOError(errno.EINVAL, str(te))
2272+
22672273
else:
22682274
if type(slices) != tuple:
22692275
msg = "setDatasetValuesByUuid: bad type for dim parameter"
@@ -2300,11 +2306,17 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
23002306
if count == 1 and len(dset.dtype) > 1:
23012307
# convert to tuple for compound singleton writes
23022308
data = tuple(data)
2303-
elif rank == 1:
2309+
if rank == 1:
23042310
s = slices[0]
2305-
dset[s] = data
2311+
try:
2312+
dset[s] = data
2313+
except TypeError as te:
2314+
raise IOError(errno.EINVAL, str(te))
23062315
else:
2307-
dset[slices] = data
2316+
try:
2317+
dset[slices] = data
2318+
except TypeError as te:
2319+
raise IOError(errno.EINVAL, str(te))
23082320

23092321
# update modified time
23102322
self.setModifiedTime(obj_uuid)

0 commit comments

Comments
 (0)