Skip to content

Commit 91e0c9a

Browse files
committed
Support unsafe casting in Delta filter
1 parent 86f5ce4 commit 91e0c9a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

numcodecs/delta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def encode(self, buf):
6767
if arr.dtype == bool:
6868
np.not_equal(arr[1:], arr[:-1], out=enc[1:])
6969
else:
70-
np.subtract(arr[1:], arr[:-1], out=enc[1:])
70+
np.subtract(arr[1:], arr[:-1], out=enc[1:], casting='unsafe')
7171

7272
return enc
7373

numcodecs/tests/test_delta.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313
# mix of dtypes: integer, float
1414
# mix of shapes: 1D, 2D, 3D
1515
# mix of orders: C, F
16+
# mix of encoding types: All available types for each arrays
1617
arrays = [
17-
np.random.randint(0, 1, size=110, dtype='?').reshape(10, 11),
18-
np.arange(1000, dtype='<i4'),
19-
np.linspace(1000, 1001, 1000, dtype='<f4').reshape(100, 10),
20-
np.random.normal(loc=1000, scale=1, size=(10, 10, 10)).astype('<f8'),
21-
np.random.randint(0, 200, size=1000, dtype='u2').astype('<u2').reshape(100, 10, order='F'),
18+
(np.random.randint(0, 1, size=110, dtype='?').reshape(10, 11), ('?','<u1','<i1')),
19+
(np.arange(1000, dtype='<i4'), ('<i4','<i2','<u4','u2')),
20+
(np.linspace(1000, 1001, 1000, dtype='<f4').reshape(100, 10), ('<f4',)),
21+
(np.random.normal(loc=1000, scale=1, size=(10, 10, 10)).astype('<f8'), ('<f8',)),
22+
(np.random.randint(0, 200, size=1000, dtype='u2').astype('<u2').reshape(100, 10, order='F'), ('<i2',)),
2223
]
2324

24-
2525
def test_encode_decode():
26-
for arr in arrays:
27-
codec = Delta(dtype=arr.dtype)
28-
check_encode_decode(arr, codec)
26+
for arr, encoding_types in arrays:
27+
for astype in encoding_types:
28+
codec = Delta(dtype=arr.dtype, astype=astype)
29+
check_encode_decode(arr, codec)
2930

3031

3132
def test_encode():
@@ -49,7 +50,7 @@ def test_repr():
4950

5051

5152
def test_backwards_compatibility():
52-
for arr in arrays:
53+
for arr,_ in arrays:
5354
codec = Delta(dtype=arr.dtype)
5455
check_backwards_compatibility(Delta.codec_id, [arr], [codec], prefix=str(arr.dtype))
5556

0 commit comments

Comments
 (0)