Skip to content

Commit 7561534

Browse files
committed
fix np.frombuffer error
1 parent 88e0691 commit 7561534

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

hsds/attr_sn.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,7 @@ async def PUT_AttributeValue(request):
851851
msg += f"but got {len(binary_data)}"
852852
log.warn(msg)
853853
raise HTTPBadRequest(reason=msg)
854-
arr = np.fromstring(binary_data, dtype=np_dtype)
855-
if attr_shape["class"] == "H5S_SCALAR":
856-
arr = arr.reshape([])
857-
else:
858-
arr = arr.reshape(np_shape) # conform to selection shape
854+
arr = bytesToArray(binary_data, np_dtype, np_shape)
859855
log.debug(f"got array {arr} from binary data")
860856
else:
861857
try:

hsds/chunk_sn.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ async def PUT_Value(request):
657657
log.warn(f"bytesToArray value error: {ve}")
658658
raise HTTPBadRequest()
659659
else:
660-
# fixed item size
660+
# fixed item size - check against number of bytes
661661
if len(input_data) % item_size != 0:
662662
msg = f"Expected request size to be a multiple of {item_size}, "
663663
msg += f"but {len(input_data)} bytes received"
@@ -668,8 +668,7 @@ async def PUT_Value(request):
668668
msg = f"expected {item_size * num_elements} bytes but got {len(input_data)}"
669669
log.warn(msg)
670670
raise HTTPBadRequest(reason=msg)
671-
672-
arr = np.fromstring(input_data, dtype=dset_dtype)
671+
arr = np.frombuffer(input_data, dtype=dset_dtype)
673672
log.debug(f"read fixed type array: {arr}")
674673

675674
if bc_shape:
@@ -1166,7 +1165,7 @@ async def POST_Value(request):
11661165
log.warn(msg)
11671166
raise HTTPBadRequest(reason=msg)
11681167
num_points = request.content_length // point_dt.itemsize
1169-
points = np.fromstring(binary_data, dtype=point_dt)
1168+
points = np.frombuffer(binary_data, dtype=point_dt)
11701169
# reshape the data based on the rank (num_points x rank)
11711170
if rank > 1:
11721171
if len(points) % rank != 0:

0 commit comments

Comments
 (0)