numcodecs 0.16.0__cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of numcodecs might be problematic. Click here for more details.

Files changed (79) hide show
  1. numcodecs/__init__.py +146 -0
  2. numcodecs/_shuffle.cpython-312-aarch64-linux-gnu.so +0 -0
  3. numcodecs/abc.py +127 -0
  4. numcodecs/astype.py +72 -0
  5. numcodecs/base64.py +26 -0
  6. numcodecs/bitround.py +80 -0
  7. numcodecs/blosc.cpython-312-aarch64-linux-gnu.so +0 -0
  8. numcodecs/bz2.py +45 -0
  9. numcodecs/categorize.py +98 -0
  10. numcodecs/checksum32.py +183 -0
  11. numcodecs/compat.py +206 -0
  12. numcodecs/compat_ext.cpython-312-aarch64-linux-gnu.so +0 -0
  13. numcodecs/delta.py +94 -0
  14. numcodecs/errors.py +26 -0
  15. numcodecs/fixedscaleoffset.py +130 -0
  16. numcodecs/fletcher32.cpython-312-aarch64-linux-gnu.so +0 -0
  17. numcodecs/gzip.py +50 -0
  18. numcodecs/jenkins.cpython-312-aarch64-linux-gnu.so +0 -0
  19. numcodecs/json.py +107 -0
  20. numcodecs/lz4.cpython-312-aarch64-linux-gnu.so +0 -0
  21. numcodecs/lzma.py +72 -0
  22. numcodecs/msgpacks.py +86 -0
  23. numcodecs/ndarray_like.py +65 -0
  24. numcodecs/packbits.py +82 -0
  25. numcodecs/pcodec.py +118 -0
  26. numcodecs/pickles.py +55 -0
  27. numcodecs/quantize.py +98 -0
  28. numcodecs/registry.py +74 -0
  29. numcodecs/shuffle.py +61 -0
  30. numcodecs/tests/__init__.py +3 -0
  31. numcodecs/tests/common.py +285 -0
  32. numcodecs/tests/package_with_entrypoint/__init__.py +11 -0
  33. numcodecs/tests/package_with_entrypoint-0.1.dist-info/entry_points.txt +2 -0
  34. numcodecs/tests/test_astype.py +74 -0
  35. numcodecs/tests/test_base64.py +81 -0
  36. numcodecs/tests/test_bitround.py +81 -0
  37. numcodecs/tests/test_blosc.py +284 -0
  38. numcodecs/tests/test_bz2.py +66 -0
  39. numcodecs/tests/test_categorize.py +87 -0
  40. numcodecs/tests/test_checksum32.py +154 -0
  41. numcodecs/tests/test_compat.py +111 -0
  42. numcodecs/tests/test_delta.py +61 -0
  43. numcodecs/tests/test_entrypoints.py +24 -0
  44. numcodecs/tests/test_entrypoints_backport.py +36 -0
  45. numcodecs/tests/test_fixedscaleoffset.py +77 -0
  46. numcodecs/tests/test_fletcher32.py +56 -0
  47. numcodecs/tests/test_gzip.py +110 -0
  48. numcodecs/tests/test_jenkins.py +150 -0
  49. numcodecs/tests/test_json.py +85 -0
  50. numcodecs/tests/test_lz4.py +83 -0
  51. numcodecs/tests/test_lzma.py +94 -0
  52. numcodecs/tests/test_msgpacks.py +126 -0
  53. numcodecs/tests/test_ndarray_like.py +48 -0
  54. numcodecs/tests/test_packbits.py +39 -0
  55. numcodecs/tests/test_pcodec.py +90 -0
  56. numcodecs/tests/test_pickles.py +61 -0
  57. numcodecs/tests/test_quantize.py +76 -0
  58. numcodecs/tests/test_registry.py +43 -0
  59. numcodecs/tests/test_shuffle.py +166 -0
  60. numcodecs/tests/test_vlen_array.py +97 -0
  61. numcodecs/tests/test_vlen_bytes.py +97 -0
  62. numcodecs/tests/test_vlen_utf8.py +91 -0
  63. numcodecs/tests/test_zarr3.py +279 -0
  64. numcodecs/tests/test_zarr3_import.py +13 -0
  65. numcodecs/tests/test_zfpy.py +104 -0
  66. numcodecs/tests/test_zlib.py +94 -0
  67. numcodecs/tests/test_zstd.py +92 -0
  68. numcodecs/version.py +21 -0
  69. numcodecs/vlen.cpython-312-aarch64-linux-gnu.so +0 -0
  70. numcodecs/zarr3.py +401 -0
  71. numcodecs/zfpy.py +113 -0
  72. numcodecs/zlib.py +42 -0
  73. numcodecs/zstd.cpython-312-aarch64-linux-gnu.so +0 -0
  74. numcodecs-0.16.0.dist-info/METADATA +66 -0
  75. numcodecs-0.16.0.dist-info/RECORD +79 -0
  76. numcodecs-0.16.0.dist-info/WHEEL +6 -0
  77. numcodecs-0.16.0.dist-info/entry_points.txt +22 -0
  78. numcodecs-0.16.0.dist-info/licenses/LICENSE.txt +21 -0
  79. numcodecs-0.16.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,279 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ import numpy as np
6
+ import pytest
7
+
8
+ if TYPE_CHECKING: # pragma: no cover
9
+ import zarr
10
+ else:
11
+ zarr = pytest.importorskip("zarr")
12
+
13
+ import zarr.storage
14
+ from zarr.core.common import JSON
15
+
16
+ import numcodecs.zarr3
17
+
18
+ pytestmark = [
19
+ pytest.mark.skipif(zarr.__version__ < "3.0.0", reason="zarr 3.0.0 or later is required"),
20
+ pytest.mark.filterwarnings("ignore:Codec 'numcodecs.*' not configured in config.*:UserWarning"),
21
+ pytest.mark.filterwarnings(
22
+ "ignore:Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations."
23
+ ),
24
+ ]
25
+
26
+ get_codec_class = zarr.registry.get_codec_class
27
+ Array = zarr.Array
28
+ BytesCodec = zarr.codecs.BytesCodec
29
+ Store = zarr.abc.store.Store
30
+ MemoryStore = zarr.storage.MemoryStore
31
+ StorePath = zarr.storage.StorePath
32
+
33
+
34
+ EXPECTED_WARNING_STR = "Numcodecs codecs are not in the Zarr version 3.*"
35
+
36
+
37
+ @pytest.fixture
38
+ def store() -> StorePath:
39
+ return StorePath(MemoryStore(read_only=False))
40
+
41
+
42
+ ALL_CODECS = [getattr(numcodecs.zarr3, cls_name) for cls_name in numcodecs.zarr3.__all__]
43
+
44
+
45
+ @pytest.mark.parametrize("codec_class", ALL_CODECS)
46
+ def test_entry_points(codec_class: type[numcodecs.zarr3._NumcodecsCodec]):
47
+ codec_name = codec_class.codec_name
48
+ assert get_codec_class(codec_name) == codec_class
49
+
50
+
51
+ @pytest.mark.parametrize("codec_class", ALL_CODECS)
52
+ def test_docstring(codec_class: type[numcodecs.zarr3._NumcodecsCodec]):
53
+ assert "See :class:`numcodecs." in codec_class.__doc__ # type: ignore[operator]
54
+
55
+
56
+ @pytest.mark.parametrize(
57
+ "codec_class",
58
+ [
59
+ numcodecs.zarr3.Blosc,
60
+ numcodecs.zarr3.LZ4,
61
+ numcodecs.zarr3.Zstd,
62
+ numcodecs.zarr3.Zlib,
63
+ numcodecs.zarr3.GZip,
64
+ numcodecs.zarr3.BZ2,
65
+ numcodecs.zarr3.LZMA,
66
+ numcodecs.zarr3.Shuffle,
67
+ ],
68
+ )
69
+ def test_generic_compressor(
70
+ store: StorePath, codec_class: type[numcodecs.zarr3._NumcodecsBytesBytesCodec]
71
+ ):
72
+ data = np.arange(0, 256, dtype="uint16").reshape((16, 16))
73
+
74
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
75
+ a = zarr.create_array(
76
+ store / "generic",
77
+ shape=data.shape,
78
+ chunks=(16, 16),
79
+ dtype=data.dtype,
80
+ fill_value=0,
81
+ compressors=[codec_class()],
82
+ )
83
+
84
+ a[:, :] = data.copy()
85
+ np.testing.assert_array_equal(data, a[:, :])
86
+
87
+
88
+ @pytest.mark.parametrize(
89
+ ("codec_class", "codec_config"),
90
+ [
91
+ (numcodecs.zarr3.Delta, {"dtype": "float32"}),
92
+ (numcodecs.zarr3.FixedScaleOffset, {"offset": 0, "scale": 25.5}),
93
+ (numcodecs.zarr3.FixedScaleOffset, {"offset": 0, "scale": 51, "astype": "uint16"}),
94
+ (numcodecs.zarr3.AsType, {"encode_dtype": "float32", "decode_dtype": "float32"}),
95
+ ],
96
+ ids=[
97
+ "delta",
98
+ "fixedscaleoffset",
99
+ "fixedscaleoffset2",
100
+ "astype",
101
+ ],
102
+ )
103
+ def test_generic_filter(
104
+ store: StorePath,
105
+ codec_class: type[numcodecs.zarr3._NumcodecsArrayArrayCodec],
106
+ codec_config: dict[str, JSON],
107
+ ):
108
+ data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
109
+
110
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
111
+ a = zarr.create_array(
112
+ store / "generic",
113
+ shape=data.shape,
114
+ chunks=(16, 16),
115
+ dtype=data.dtype,
116
+ fill_value=0,
117
+ filters=[
118
+ codec_class(**codec_config),
119
+ ],
120
+ )
121
+
122
+ a[:, :] = data.copy()
123
+ a = zarr.open_array(store / "generic", mode="r")
124
+ np.testing.assert_array_equal(data, a[:, :])
125
+
126
+
127
+ def test_generic_filter_bitround(store: StorePath):
128
+ data = np.linspace(0, 1, 256, dtype="float32").reshape((16, 16))
129
+
130
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
131
+ a = zarr.create_array(
132
+ store / "generic_bitround",
133
+ shape=data.shape,
134
+ chunks=(16, 16),
135
+ dtype=data.dtype,
136
+ fill_value=0,
137
+ filters=[numcodecs.zarr3.BitRound(keepbits=3)],
138
+ )
139
+
140
+ a[:, :] = data.copy()
141
+ a = zarr.open_array(store / "generic_bitround", mode="r")
142
+ assert np.allclose(data, a[:, :], atol=0.1)
143
+
144
+
145
+ def test_generic_filter_quantize(store: StorePath):
146
+ data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
147
+
148
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
149
+ a = zarr.create_array(
150
+ store / "generic_quantize",
151
+ shape=data.shape,
152
+ chunks=(16, 16),
153
+ dtype=data.dtype,
154
+ fill_value=0,
155
+ filters=[numcodecs.zarr3.Quantize(digits=3)],
156
+ )
157
+
158
+ a[:, :] = data.copy()
159
+ a = zarr.open_array(store / "generic_quantize", mode="r")
160
+ assert np.allclose(data, a[:, :], atol=0.001)
161
+
162
+
163
+ def test_generic_filter_packbits(store: StorePath):
164
+ data = np.zeros((16, 16), dtype="bool")
165
+ data[0:4, :] = True
166
+
167
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
168
+ a = zarr.create_array(
169
+ store / "generic_packbits",
170
+ shape=data.shape,
171
+ chunks=(16, 16),
172
+ dtype=data.dtype,
173
+ fill_value=0,
174
+ filters=[numcodecs.zarr3.PackBits()],
175
+ )
176
+
177
+ a[:, :] = data.copy()
178
+ a = zarr.open_array(store / "generic_packbits", mode="r")
179
+ np.testing.assert_array_equal(data, a[:, :])
180
+
181
+ with pytest.raises(ValueError, match=".*requires bool dtype.*"):
182
+ zarr.create_array(
183
+ store / "generic_packbits_err",
184
+ shape=data.shape,
185
+ chunks=(16, 16),
186
+ dtype="uint32",
187
+ fill_value=0,
188
+ filters=[numcodecs.zarr3.PackBits()],
189
+ )
190
+
191
+
192
+ @pytest.mark.parametrize(
193
+ "codec_class",
194
+ [
195
+ numcodecs.zarr3.CRC32,
196
+ numcodecs.zarr3.CRC32C,
197
+ numcodecs.zarr3.Adler32,
198
+ numcodecs.zarr3.Fletcher32,
199
+ numcodecs.zarr3.JenkinsLookup3,
200
+ ],
201
+ )
202
+ def test_generic_checksum(
203
+ store: StorePath, codec_class: type[numcodecs.zarr3._NumcodecsBytesBytesCodec]
204
+ ):
205
+ data = np.linspace(0, 10, 256, dtype="float32").reshape((16, 16))
206
+
207
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
208
+ a = zarr.create_array(
209
+ store / "generic_checksum",
210
+ shape=data.shape,
211
+ chunks=(16, 16),
212
+ dtype=data.dtype,
213
+ fill_value=0,
214
+ compressors=[codec_class()],
215
+ )
216
+
217
+ a[:, :] = data.copy()
218
+ a = zarr.open_array(store / "generic_checksum", mode="r")
219
+ np.testing.assert_array_equal(data, a[:, :])
220
+
221
+
222
+ @pytest.mark.parametrize("codec_class", [numcodecs.zarr3.PCodec, numcodecs.zarr3.ZFPY])
223
+ def test_generic_bytes_codec(
224
+ store: StorePath, codec_class: type[numcodecs.zarr3._NumcodecsArrayBytesCodec]
225
+ ):
226
+ try:
227
+ codec_class()._codec # noqa: B018
228
+ except ValueError as e: # pragma: no cover
229
+ if "codec not available" in str(e):
230
+ pytest.xfail(f"{codec_class.codec_name} is not available: {e}")
231
+ else:
232
+ raise
233
+ except ImportError as e: # pragma: no cover
234
+ pytest.xfail(f"{codec_class.codec_name} is not available: {e}")
235
+
236
+ data = np.arange(0, 256, dtype="float32").reshape((16, 16))
237
+
238
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
239
+ a = zarr.create_array(
240
+ store / "generic",
241
+ shape=data.shape,
242
+ chunks=(16, 16),
243
+ dtype=data.dtype,
244
+ fill_value=0,
245
+ serializer=codec_class(),
246
+ )
247
+
248
+ a[:, :] = data.copy()
249
+ np.testing.assert_array_equal(data, a[:, :])
250
+
251
+
252
+ def test_delta_astype(store: StorePath):
253
+ data = np.linspace(0, 10, 256, dtype="i8").reshape((16, 16))
254
+
255
+ with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR):
256
+ a = zarr.create_array(
257
+ store / "generic",
258
+ shape=data.shape,
259
+ chunks=(16, 16),
260
+ dtype=data.dtype,
261
+ fill_value=0,
262
+ filters=[
263
+ numcodecs.zarr3.Delta(dtype="i8", astype="i2"), # type: ignore[arg-type]
264
+ ],
265
+ )
266
+
267
+ a[:, :] = data.copy()
268
+ a = zarr.open_array(store / "generic", mode="r")
269
+ np.testing.assert_array_equal(data, a[:, :])
270
+
271
+
272
+ def test_repr():
273
+ codec = numcodecs.zarr3.LZ4(level=5)
274
+ assert repr(codec) == "LZ4(codec_name='numcodecs.lz4', codec_config={'level': 5})"
275
+
276
+
277
+ def test_to_dict():
278
+ codec = numcodecs.zarr3.LZ4(level=5)
279
+ assert codec.to_dict() == {"name": "numcodecs.lz4", "configuration": {"level": 5}}
@@ -0,0 +1,13 @@
1
+ from __future__ import annotations
2
+
3
+ import pytest
4
+
5
+
6
+ def test_zarr3_import():
7
+ ERROR_MESSAGE_MATCH = "zarr 3.0.0 or later.*"
8
+
9
+ try:
10
+ import zarr # noqa: F401
11
+ except ImportError: # pragma: no cover
12
+ with pytest.raises(ImportError, match=ERROR_MESSAGE_MATCH):
13
+ import numcodecs.zarr3 # noqa: F401
@@ -0,0 +1,104 @@
1
+ from types import ModuleType
2
+ from typing import cast
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ try:
8
+ # noinspection PyProtectedMember
9
+ from numcodecs.zfpy import ZFPY, _zfpy
10
+ except ImportError: # pragma: no cover
11
+ pytest.skip("ZFPY not available", allow_module_level=True)
12
+
13
+
14
+ from numcodecs.tests.common import (
15
+ check_backwards_compatibility,
16
+ check_config,
17
+ check_encode_decode_array,
18
+ check_err_decode_object_buffer,
19
+ check_err_encode_object_buffer,
20
+ check_repr,
21
+ )
22
+
23
+ _zfpy = cast(ModuleType, _zfpy)
24
+
25
+
26
+ codecs = [
27
+ ZFPY(mode=_zfpy.mode_fixed_rate, rate=-1),
28
+ ZFPY(),
29
+ ZFPY(mode=_zfpy.mode_fixed_accuracy, tolerance=-1),
30
+ ZFPY(mode=_zfpy.mode_fixed_precision, precision=-1),
31
+ ]
32
+
33
+
34
+ # mix of dtypes: integer, float, bool, string
35
+ # mix of shapes: 1D, 2D, 3D
36
+ # mix of orders: C, F
37
+ arrays = [
38
+ np.linspace(1000, 1001, 1000, dtype="f4"),
39
+ np.linspace(1000, 1001, 1000, dtype="f8"),
40
+ np.random.normal(loc=1000, scale=1, size=(100, 10)),
41
+ np.random.normal(loc=1000, scale=1, size=(10, 10, 10)),
42
+ np.random.normal(loc=1000, scale=1, size=(2, 5, 10, 10)),
43
+ np.random.randint(-(2**31), -(2**31) + 20, size=1000, dtype="i4").reshape(100, 10),
44
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").reshape(10, 10, 10),
45
+ ]
46
+
47
+
48
+ def test_encode_decode():
49
+ for arr in arrays:
50
+ if arr.dtype in (np.int32, np.int64):
51
+ codec = [codecs[-1]]
52
+ else:
53
+ codec = codecs
54
+ for code in codec:
55
+ check_encode_decode_array(arr, code)
56
+
57
+
58
+ def test_config():
59
+ for codec in codecs:
60
+ check_config(codec)
61
+
62
+
63
+ def test_repr():
64
+ check_repr("ZFPY(mode=4, tolerance=0.001, rate=-1, precision=-1)")
65
+
66
+
67
+ def test_backwards_compatibility():
68
+ for code in codecs:
69
+ if code.mode == _zfpy.mode_fixed_rate:
70
+ codec = [code]
71
+ check_backwards_compatibility(ZFPY.codec_id, arrays, codec)
72
+ else:
73
+ check_backwards_compatibility(ZFPY.codec_id, arrays[: len(arrays) - 2], codecs)
74
+
75
+
76
+ def test_err_decode_object_buffer():
77
+ check_err_decode_object_buffer(ZFPY())
78
+
79
+
80
+ def test_err_encode_object_buffer():
81
+ check_err_encode_object_buffer(ZFPY())
82
+
83
+
84
+ def test_err_encode_list():
85
+ data = ['foo', 'bar', 'baz']
86
+ for codec in codecs:
87
+ with pytest.raises(TypeError):
88
+ codec.encode(data)
89
+
90
+
91
+ def test_err_encode_non_contiguous():
92
+ # non-contiguous memory
93
+ arr = np.arange(1000, dtype='i4')[::2]
94
+ for codec in codecs:
95
+ with pytest.raises(ValueError):
96
+ codec.encode(arr)
97
+
98
+
99
+ def test_err_encode_fortran_array():
100
+ # fortran array
101
+ arr = np.asfortranarray(np.random.normal(loc=1000, scale=1, size=(5, 10, 20)))
102
+ for codec in codecs:
103
+ with pytest.raises(ValueError):
104
+ codec.encode(arr)
@@ -0,0 +1,94 @@
1
+ import itertools
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ from numcodecs.tests.common import (
7
+ check_backwards_compatibility,
8
+ check_config,
9
+ check_encode_decode,
10
+ check_err_decode_object_buffer,
11
+ check_err_encode_object_buffer,
12
+ check_repr,
13
+ )
14
+ from numcodecs.zlib import Zlib
15
+
16
+ codecs = [
17
+ Zlib(),
18
+ Zlib(level=-1),
19
+ Zlib(level=0),
20
+ Zlib(level=1),
21
+ Zlib(level=5),
22
+ Zlib(level=9),
23
+ ]
24
+
25
+
26
+ # mix of dtypes: integer, float, bool, string
27
+ # mix of shapes: 1D, 2D, 3D
28
+ # mix of orders: C, F
29
+ arrays = [
30
+ np.arange(1000, dtype='i4'),
31
+ np.linspace(1000, 1001, 1000, dtype='f8'),
32
+ np.random.normal(loc=1000, scale=1, size=(100, 10)),
33
+ np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
34
+ np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
35
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('M8[ns]'),
36
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
37
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
38
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
39
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[ns]'),
40
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[ns]'),
41
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
42
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
43
+ ]
44
+
45
+
46
+ def test_encode_decode():
47
+ for arr, codec in itertools.product(arrays, codecs):
48
+ check_encode_decode(arr, codec)
49
+
50
+
51
+ def test_config():
52
+ codec = Zlib(level=3)
53
+ check_config(codec)
54
+
55
+
56
+ def test_repr():
57
+ check_repr("Zlib(level=3)")
58
+
59
+
60
+ def test_eq():
61
+ assert Zlib() == Zlib()
62
+ assert not Zlib() != Zlib()
63
+ assert Zlib(1) == Zlib(1)
64
+ assert Zlib(1) != Zlib(9)
65
+ assert Zlib() != 'foo'
66
+ assert 'foo' != Zlib()
67
+ assert not Zlib() == 'foo'
68
+
69
+
70
+ def test_backwards_compatibility():
71
+ check_backwards_compatibility(Zlib.codec_id, arrays, codecs)
72
+
73
+
74
+ def test_err_decode_object_buffer():
75
+ check_err_decode_object_buffer(Zlib())
76
+
77
+
78
+ def test_err_encode_object_buffer():
79
+ check_err_encode_object_buffer(Zlib())
80
+
81
+
82
+ def test_err_encode_list():
83
+ data = ['foo', 'bar', 'baz']
84
+ for codec in codecs:
85
+ with pytest.raises(TypeError):
86
+ codec.encode(data)
87
+
88
+
89
+ def test_err_encode_non_contiguous():
90
+ # non-contiguous memory
91
+ arr = np.arange(1000, dtype='i4')[::2]
92
+ for codec in codecs:
93
+ with pytest.raises(ValueError):
94
+ codec.encode(arr)
@@ -0,0 +1,92 @@
1
+ import itertools
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ try:
7
+ from numcodecs.zstd import Zstd
8
+ except ImportError: # pragma: no cover
9
+ pytest.skip("numcodecs.zstd not available", allow_module_level=True)
10
+
11
+
12
+ from numcodecs.tests.common import (
13
+ check_backwards_compatibility,
14
+ check_config,
15
+ check_encode_decode,
16
+ check_err_decode_object_buffer,
17
+ check_err_encode_object_buffer,
18
+ check_repr,
19
+ )
20
+
21
+ codecs = [
22
+ Zstd(),
23
+ Zstd(level=-1),
24
+ Zstd(level=0),
25
+ Zstd(level=1),
26
+ Zstd(level=10),
27
+ Zstd(level=22),
28
+ Zstd(level=100),
29
+ Zstd(checksum=True),
30
+ Zstd(level=0, checksum=True),
31
+ Zstd(level=22, checksum=True),
32
+ ]
33
+
34
+
35
+ # mix of dtypes: integer, float, bool, string
36
+ # mix of shapes: 1D, 2D, 3D
37
+ # mix of orders: C, F
38
+ arrays = [
39
+ np.arange(1000, dtype="i4"),
40
+ np.linspace(1000, 1001, 1000, dtype="f8"),
41
+ np.random.normal(loc=1000, scale=1, size=(100, 10)),
42
+ np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
43
+ np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
44
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('M8[ns]'),
45
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
46
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
47
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
48
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[ns]'),
49
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[ns]'),
50
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
51
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
52
+ ]
53
+
54
+
55
+ def test_encode_decode():
56
+ for arr, codec in itertools.product(arrays, codecs):
57
+ check_encode_decode(arr, codec)
58
+
59
+
60
+ def test_config():
61
+ for codec in codecs:
62
+ check_config(codec)
63
+
64
+
65
+ def test_repr():
66
+ check_repr("Zstd(level=3)")
67
+
68
+
69
+ def test_backwards_compatibility():
70
+ check_backwards_compatibility(Zstd.codec_id, arrays, codecs)
71
+
72
+
73
+ def test_err_decode_object_buffer():
74
+ check_err_decode_object_buffer(Zstd())
75
+
76
+
77
+ def test_err_encode_object_buffer():
78
+ check_err_encode_object_buffer(Zstd())
79
+
80
+
81
+ def test_checksum():
82
+ data = np.arange(0, 64, dtype="uint8")
83
+ assert len(Zstd(level=0, checksum=False).encode(data)) + 4 == len(
84
+ Zstd(level=0, checksum=True).encode(data)
85
+ )
86
+
87
+
88
+ def test_native_functions():
89
+ # Note, these assertions might need to be changed for new versions of zstd
90
+ assert Zstd.default_level() == 3
91
+ assert Zstd.min_level() == -131072
92
+ assert Zstd.max_level() == 22
numcodecs/version.py ADDED
@@ -0,0 +1,21 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
6
+ TYPE_CHECKING = False
7
+ if TYPE_CHECKING:
8
+ from typing import Tuple
9
+ from typing import Union
10
+
11
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
12
+ else:
13
+ VERSION_TUPLE = object
14
+
15
+ version: str
16
+ __version__: str
17
+ __version_tuple__: VERSION_TUPLE
18
+ version_tuple: VERSION_TUPLE
19
+
20
+ __version__ = version = '0.16.0'
21
+ __version_tuple__ = version_tuple = (0, 16, 0)