Skip to content

Commit ddd4d8a

Browse files
Added tests to verify handling of non-numpy inputs.
1 parent 98b6966 commit ddd4d8a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

numcodecs/tests/test_json.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,23 @@ def test_repr():
5454

5555
def test_backwards_compatibility():
5656
check_backwards_compatibility(JSON.codec_id, arrays, codecs)
57+
58+
59+
def test_non_numpy_inputs():
60+
# numpy will infer a range of different shapes and dtypes for these inputs.
61+
# Make sure that round-tripping through encode preserves this.
62+
data = [
63+
[0, 1],
64+
[[0, 1], [2, 3]],
65+
[[0], [1], [2, 3]],
66+
[[[0, 0]], [[1, 1]], [[2, 3]]],
67+
["1"],
68+
["11", "11"],
69+
["11", "1", "1"],
70+
[{}],
71+
[{"key":"value"}, ["list", "of", "strings"]],
72+
]
73+
for input_data in data:
74+
for codec in codecs:
75+
output_data = codec.decode(codec.encode(input_data))
76+
assert np.array_equal(np.array(input_data), output_data)

0 commit comments

Comments
 (0)