Skip to content

Commit

Permalink
Fix jsonToArray on None array
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Nov 1, 2023
1 parent 0bf6bb9 commit aad10f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hsds/util/arrayUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def fillVlenArray(rank, data, arr, index):
index += 1
return index

if data_json is None:
return np.array([]).astype(data_dtype)

# need some special conversion for compound types --
# each element must be a tuple, but the JSON decoder
# gives us a list instead.
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/array_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,17 @@ def testGetBroadcastShape(self):
bcshape = getBroadcastShape([2, 3, 5], 15)
self.assertEqual(bcshape, [3, 5])

def testJsonToArrayOnNoneCompoundArray(self):
# compound type
dt = np.dtype([("a", "i4"), ("b", "S5")])
shape = [1,]
data = None

arr = jsonToArray(shape, dt, data)

self.assertEqual(len(arr), 0)
self.assertEqual(arr.dtype, dt)


if __name__ == "__main__":
# setup test files
Expand Down

0 comments on commit aad10f6

Please sign in to comment.