Skip to content

Commit 43e63ad

Browse files
committed
add format arg to setDataValues function
1 parent ff00a4d commit 43e63ad

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

h5json/hdf5db.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,16 +2220,17 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
22202220
if dset is None:
22212221
msg = "Dataset: " + obj_uuid + " not found"
22222222
self.log.info(msg)
2223-
raise IOError(errno.ENXIO, msg)
2223+
raise IOError(errno.ENXIO, msg)
22242224

22252225
dt = dset.dtype
22262226
typeItem = getTypeItem(dt)
22272227
itemSize = getItemSize(typeItem)
22282228
if itemSize == "H5T_VARIABLE" and format == "binary":
22292229
msg = "Only JSON is supported for for this data type"
22302230
self.log.info(msg)
2231-
raise IOError(errno.EINVAL, msg)
2232-
2231+
raise IOError(errno.EINVAL, msg)
2232+
2233+
22332234
# need some special conversion for compound types --
22342235
# each element must be a tuple, but the JSON decoder
22352236
# gives us a list instead.
@@ -2251,8 +2252,8 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
22512252
if slices is None:
22522253
# write entire dataset
22532254
if format == "binary":
2254-
if len(data) != dset.size:
2255-
msg = "Expected " + dset.size + " bytes, but got: " + len(data)
2255+
if len(data) != (dset.size * itemSize):
2256+
msg = "Expected " + (dset.size * itemSize) + " bytes, but got: " + len(data)
22562257
self.log.info(msg)
22572258
raise IOError(errno.EINVAL, msg)
22582259
arr = np.fromstring(data, dtype=dset.dtype)
@@ -2271,23 +2272,35 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
22712272
self.log.error("setDatasetValuesByUuid: number of dims in selection not same as rank")
22722273
return False
22732274
else:
2274-
22752275
npoints = 1
22762276
for i in range(rank):
22772277
s = slices[i]
22782278
count = (s.stop - s.start) // s.step
22792279
npoints *= count
22802280
if count <= 0:
22812281
self.log.error("invalid slice specification")
2282-
if count == 1 and len(dset.dtype) > 1:
2283-
# convert to tuple for compound singleton writes
2284-
data = tuple(data)
2285-
2286-
if rank == 1:
2287-
slice = slices[0]
2288-
dset[slice] = data
2282+
2283+
if format == "binary":
2284+
np_shape = []
2285+
for i in range(rank):
2286+
s = slices[i]
2287+
np_shape.append( (s.stop - s.start) )
2288+
arr = np.fromstring(data, dtype=dset.dtype)
2289+
arr.reshape(np_shape)
2290+
if rank == 1:
2291+
s = slices[0]
2292+
dset[s] = arr
2293+
else:
2294+
dset[slices] = arr
22892295
else:
2290-
dset[slices] = data
2296+
if count == 1 and len(dset.dtype) > 1:
2297+
# convert to tuple for compound singleton writes
2298+
data = tuple(data)
2299+
elif rank == 1:
2300+
s = slices[0]
2301+
dset[s] = data
2302+
else:
2303+
dset[slices] = data
22912304

22922305
# update modified time
22932306
self.setModifiedTime(obj_uuid)
@@ -2297,7 +2310,7 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
22972310
setDatasetValuesByPointSelection - Update the dataset values using the given
22982311
data and point selection
22992312
"""
2300-
def setDatasetValuesByPointSelection(self, obj_uuid, data, points):
2313+
def setDatasetValuesByPointSelection(self, obj_uuid, data, points, format="json"):
23012314
dset = self.getDatasetObjByUuid(obj_uuid)
23022315
# need some special conversion for compound types --
23032316
# each element must be a tuple, but the JSON decoder

0 commit comments

Comments
 (0)