Skip to content

Commit

Permalink
Add test for empty jsonToArray
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Jul 12, 2023
1 parent f97925d commit 64c9e59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hsds/util/arrayUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def fillVlenArray(rank, data, arr, index):
if arr.shape != data_shape:
arr = arr.reshape(data_shape) # reshape to match selection
else:
arr = np.array([], dtype=data_dtype)
arr = np.array([]).astype(data_dtype)

return arr

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/array_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,20 @@ def testIndexIterator(self):
cnt += 1
self.assertEqual(cnt, 20)

def testJsonToArrayOnNoneArray(self):
data_dtype = np.dtype("i4")
data_shape = [0, ]
data_json = [None]
arr = None

try:
arr = jsonToArray(data_shape, data_dtype, data_json)
except Exception as e:
print(f"Exception while testing jsonToArray on array with None elements: {e}")

self.assertTrue(len(arr) == 0)
self.assertTrue(arr.dtype == data_dtype)


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

0 comments on commit 64c9e59

Please sign in to comment.