numcodecs 0.16.4__cp313-cp313-macosx_11_0_arm64.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.
Files changed (87) hide show
  1. numcodecs/__init__.py +146 -0
  2. numcodecs/_shuffle.cpython-313-darwin.so +0 -0
  3. numcodecs/abc.py +126 -0
  4. numcodecs/astype.py +72 -0
  5. numcodecs/base64.py +26 -0
  6. numcodecs/bitround.py +80 -0
  7. numcodecs/blosc.cpython-313-darwin.so +0 -0
  8. numcodecs/bz2.py +45 -0
  9. numcodecs/categorize.py +98 -0
  10. numcodecs/checksum32.py +189 -0
  11. numcodecs/compat.py +206 -0
  12. numcodecs/compat_ext.cpython-313-darwin.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-313-darwin.so +0 -0
  17. numcodecs/gzip.py +50 -0
  18. numcodecs/jenkins.cpython-313-darwin.so +0 -0
  19. numcodecs/json.py +107 -0
  20. numcodecs/lz4.cpython-313-darwin.so +0 -0
  21. numcodecs/lzma.py +71 -0
  22. numcodecs/msgpacks.py +86 -0
  23. numcodecs/ndarray_like.py +65 -0
  24. numcodecs/packbits.py +82 -0
  25. numcodecs/pcodec.py +119 -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 +275 -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 +290 -0
  38. numcodecs/tests/test_bz2.py +66 -0
  39. numcodecs/tests/test_categorize.py +87 -0
  40. numcodecs/tests/test_checksum32.py +199 -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_pyzstd.py +76 -0
  58. numcodecs/tests/test_quantize.py +76 -0
  59. numcodecs/tests/test_registry.py +43 -0
  60. numcodecs/tests/test_shuffle.py +166 -0
  61. numcodecs/tests/test_vlen_array.py +97 -0
  62. numcodecs/tests/test_vlen_bytes.py +93 -0
  63. numcodecs/tests/test_vlen_utf8.py +91 -0
  64. numcodecs/tests/test_zarr3.py +48 -0
  65. numcodecs/tests/test_zarr3_import.py +13 -0
  66. numcodecs/tests/test_zfpy.py +104 -0
  67. numcodecs/tests/test_zlib.py +94 -0
  68. numcodecs/tests/test_zstd.py +189 -0
  69. numcodecs/version.py +34 -0
  70. numcodecs/vlen.cpython-313-darwin.so +0 -0
  71. numcodecs/zarr3.py +67 -0
  72. numcodecs/zfpy.py +112 -0
  73. numcodecs/zlib.py +42 -0
  74. numcodecs/zstd.cpython-313-darwin.so +0 -0
  75. numcodecs-0.16.4.dist-info/METADATA +67 -0
  76. numcodecs-0.16.4.dist-info/RECORD +87 -0
  77. numcodecs-0.16.4.dist-info/WHEEL +6 -0
  78. numcodecs-0.16.4.dist-info/licenses/LICENSE.txt +21 -0
  79. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSE.txt +31 -0
  80. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSES/BITSHUFFLE.txt +21 -0
  81. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSES/FASTLZ.txt +20 -0
  82. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSES/LZ4.txt +25 -0
  83. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSES/SNAPPY.txt +28 -0
  84. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSES/STDINT.txt +29 -0
  85. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSES/ZLIB-NG.txt +17 -0
  86. numcodecs-0.16.4.dist-info/licenses/c-blosc/LICENSES/ZLIB.txt +22 -0
  87. numcodecs-0.16.4.dist-info/top_level.txt +1 -0
@@ -0,0 +1,85 @@
1
+ import itertools
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ from numcodecs.json import JSON
7
+ from numcodecs.tests.common import (
8
+ check_backwards_compatibility,
9
+ check_config,
10
+ check_encode_decode_array,
11
+ check_repr,
12
+ greetings,
13
+ )
14
+
15
+ codecs = [
16
+ JSON(),
17
+ JSON(indent=True),
18
+ ]
19
+
20
+
21
+ # object array with strings
22
+ # object array with mix strings / nans
23
+ # object array with mix of string, int, float
24
+ # ...
25
+ arrays = [
26
+ np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
27
+ np.array([['foo', 'bar', np.nan]] * 300, dtype=object),
28
+ np.array(['foo', 1.0, 2] * 300, dtype=object),
29
+ np.arange(1000, dtype='i4'),
30
+ np.array(['foo', 'bar', 'baz'] * 300),
31
+ np.array(['foo', ['bar', 1.0, 2], {'a': 'b', 'c': 42}] * 300, dtype=object),
32
+ np.array(greetings * 100),
33
+ np.array(greetings * 100, dtype=object),
34
+ np.array([[0, 1], [2, 3]], dtype=object),
35
+ ]
36
+
37
+
38
+ def test_encode_decode():
39
+ for arr, codec in itertools.product(arrays, codecs):
40
+ check_encode_decode_array(arr, codec)
41
+
42
+
43
+ def test_config():
44
+ for codec in codecs:
45
+ check_config(codec)
46
+
47
+
48
+ def test_repr():
49
+ r = (
50
+ "JSON(encoding='utf-8', allow_nan=True, check_circular=True, ensure_ascii=True,\n"
51
+ " indent=None, separators=(',', ':'), skipkeys=False, sort_keys=True,\n"
52
+ " strict=True)"
53
+ )
54
+ check_repr(r)
55
+
56
+
57
+ def test_backwards_compatibility():
58
+ check_backwards_compatibility(JSON.codec_id, arrays, codecs)
59
+
60
+
61
+ @pytest.mark.parametrize(
62
+ ('input_data', 'dtype'),
63
+ [
64
+ ([0, 1], None),
65
+ ([[0, 1], [2, 3]], None),
66
+ ([[0], [1], [2, 3]], object),
67
+ ([[[0, 0]], [[1, 1]], [[2, 3]]], None),
68
+ (["1"], None),
69
+ (["11", "11"], None),
70
+ (["11", "1", "1"], None),
71
+ ([{}], None),
72
+ ([{"key": "value"}, ["list", "of", "strings"]], object),
73
+ ([0], None),
74
+ ([{'hi': 0}], "object"),
75
+ (["hi"], "object"),
76
+ (0, None),
77
+ ],
78
+ )
79
+ def test_non_numpy_inputs(input_data, dtype):
80
+ # numpy will infer a range of different shapes and dtypes for these inputs.
81
+ # Make sure that round-tripping through encode preserves this.
82
+ data = np.array(input_data, dtype=dtype)
83
+ for codec in codecs:
84
+ output_data = codec.decode(codec.encode(data))
85
+ assert input_data == output_data.tolist()
@@ -0,0 +1,83 @@
1
+ import itertools
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ try:
7
+ from numcodecs.lz4 import LZ4
8
+ except ImportError: # pragma: no cover
9
+ pytest.skip("numcodecs.lz4 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_max_buffer_size,
19
+ check_repr,
20
+ )
21
+
22
+ codecs = [
23
+ LZ4(),
24
+ LZ4(acceleration=-1),
25
+ LZ4(acceleration=0),
26
+ LZ4(acceleration=1),
27
+ LZ4(acceleration=10),
28
+ LZ4(acceleration=100),
29
+ LZ4(acceleration=1000000),
30
+ ]
31
+
32
+
33
+ # mix of dtypes: integer, float, bool, string
34
+ # mix of shapes: 1D, 2D, 3D
35
+ # mix of orders: C, F
36
+ arrays = [
37
+ np.arange(1000, dtype='i4'),
38
+ np.linspace(1000, 1001, 1000, dtype='f8'),
39
+ np.random.normal(loc=1000, scale=1, size=(100, 10)),
40
+ np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
41
+ np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
42
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('M8[ns]'),
43
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
44
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
45
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
46
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[ns]'),
47
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[ns]'),
48
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
49
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
50
+ ]
51
+
52
+
53
+ def test_encode_decode():
54
+ for arr, codec in itertools.product(arrays, codecs):
55
+ check_encode_decode(arr, codec)
56
+
57
+
58
+ def test_config():
59
+ for codec in codecs:
60
+ check_config(codec)
61
+
62
+
63
+ def test_repr():
64
+ check_repr("LZ4(acceleration=1)")
65
+ check_repr("LZ4(acceleration=100)")
66
+
67
+
68
+ def test_backwards_compatibility():
69
+ check_backwards_compatibility(LZ4.codec_id, arrays, codecs)
70
+
71
+
72
+ def test_err_decode_object_buffer():
73
+ check_err_decode_object_buffer(LZ4())
74
+
75
+
76
+ def test_err_encode_object_buffer():
77
+ check_err_encode_object_buffer(LZ4())
78
+
79
+
80
+ def test_max_buffer_size():
81
+ for codec in codecs:
82
+ assert codec.max_buffer_size == 0x7E000000
83
+ check_max_buffer_size(codec)
@@ -0,0 +1,94 @@
1
+ import itertools
2
+ import unittest
3
+ from types import ModuleType
4
+ from typing import cast
5
+
6
+ import numpy as np
7
+ import pytest
8
+
9
+ try:
10
+ # noinspection PyProtectedMember
11
+ from numcodecs.lzma import LZMA, _lzma
12
+ except ImportError as e: # pragma: no cover
13
+ raise unittest.SkipTest("LZMA not available") from e
14
+
15
+
16
+ from numcodecs.tests.common import (
17
+ check_backwards_compatibility,
18
+ check_config,
19
+ check_encode_decode,
20
+ check_err_decode_object_buffer,
21
+ check_err_encode_object_buffer,
22
+ check_repr,
23
+ )
24
+
25
+ _lzma = cast(ModuleType, _lzma)
26
+
27
+ codecs = [
28
+ LZMA(),
29
+ LZMA(preset=1),
30
+ LZMA(preset=5),
31
+ LZMA(preset=9),
32
+ LZMA(format=_lzma.FORMAT_RAW, filters=[{"id": _lzma.FILTER_LZMA2, "preset": 1}]),
33
+ ]
34
+
35
+
36
+ # mix of dtypes: integer, float, bool, string
37
+ # mix of shapes: 1D, 2D, 3D
38
+ # mix of orders: C, F
39
+ arrays = [
40
+ np.arange(1000, dtype='i4'),
41
+ np.linspace(1000, 1001, 1000, dtype='f8'),
42
+ np.random.normal(loc=1000, scale=1, size=(100, 10)),
43
+ np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
44
+ np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
45
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('M8[ns]'),
46
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
47
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
48
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
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[ns]'),
51
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
52
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
53
+ ]
54
+
55
+
56
+ def test_encode_decode():
57
+ for arr, codec in itertools.product(arrays, codecs):
58
+ check_encode_decode(arr, codec)
59
+
60
+
61
+ def test_config():
62
+ codec = LZMA(preset=1, format=_lzma.FORMAT_XZ, check=_lzma.CHECK_NONE, filters=None)
63
+ check_config(codec)
64
+
65
+
66
+ def test_repr():
67
+ check_repr('LZMA(format=1, check=0, preset=1, filters=None)')
68
+
69
+
70
+ def test_backwards_compatibility():
71
+ check_backwards_compatibility(LZMA.codec_id, arrays, codecs)
72
+
73
+
74
+ def test_err_decode_object_buffer():
75
+ check_err_decode_object_buffer(LZMA())
76
+
77
+
78
+ def test_err_encode_object_buffer():
79
+ check_err_encode_object_buffer(LZMA())
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,126 @@
1
+ import unittest
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ try:
7
+ from numcodecs.msgpacks import MsgPack
8
+ except ImportError as e: # pragma: no cover
9
+ raise unittest.SkipTest("msgpack not available") from e
10
+
11
+
12
+ from numcodecs.tests.common import (
13
+ check_backwards_compatibility,
14
+ check_config,
15
+ check_encode_decode_array,
16
+ check_repr,
17
+ greetings,
18
+ )
19
+
20
+ # object array with strings
21
+ # object array with mix strings / nans
22
+ # object array with mix of string, int, float
23
+ # ...
24
+ arrays = [
25
+ np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
26
+ np.array([['foo', 'bar', np.nan]] * 300, dtype=object),
27
+ np.array(['foo', 1.0, 2] * 300, dtype=object),
28
+ np.arange(1000, dtype='i4'),
29
+ np.array(['foo', 'bar', 'baz'] * 300),
30
+ np.array(['foo', ['bar', 1.0, 2], {'a': 'b', 'c': 42}] * 300, dtype=object),
31
+ np.array(greetings * 100),
32
+ np.array(greetings * 100, dtype=object),
33
+ np.array([b'foo', b'bar', b'baz'] * 300, dtype=object),
34
+ np.array([g.encode('utf-8') for g in greetings] * 100, dtype=object),
35
+ np.array([[0, 1], [2, 3]], dtype=object),
36
+ ]
37
+
38
+
39
+ def test_encode_decode():
40
+ for arr in arrays:
41
+ check_encode_decode_array(arr, MsgPack())
42
+
43
+
44
+ def test_config():
45
+ check_config(MsgPack())
46
+
47
+
48
+ def test_repr():
49
+ check_repr("MsgPack(raw=False, use_bin_type=True, use_single_float=False)")
50
+ check_repr("MsgPack(raw=True, use_bin_type=False, use_single_float=True)")
51
+
52
+
53
+ def test_backwards_compatibility():
54
+ codec = MsgPack()
55
+ check_backwards_compatibility(codec.codec_id, arrays, [codec])
56
+
57
+
58
+ @pytest.mark.filterwarnings(
59
+ "ignore:Creating an ndarray from ragged nested sequences .* is deprecated.*"
60
+ )
61
+ @pytest.mark.parametrize(
62
+ ("input_data", "dtype"),
63
+ [
64
+ ([0, 1], None),
65
+ ([[0, 1], [2, 3]], None),
66
+ ([[0], [1], [2, 3]], object),
67
+ ([[[0, 0]], [[1, 1]], [[2, 3]]], None),
68
+ (["1"], None),
69
+ (["11", "11"], None),
70
+ (["11", "1", "1"], None),
71
+ ([{}], None),
72
+ ([{"key": "value"}, ["list", "of", "strings"]], object),
73
+ ([b"1"], None),
74
+ ([b"11", b"11"], None),
75
+ ([b"11", b"1", b"1"], None),
76
+ ([{b"key": b"value"}, [b"list", b"of", b"strings"]], object),
77
+ ],
78
+ )
79
+ def test_non_numpy_inputs(input_data, dtype):
80
+ codec = MsgPack()
81
+ # numpy will infer a range of different shapes and dtypes for these inputs.
82
+ # Make sure that round-tripping through encode preserves this.
83
+ actual = codec.decode(codec.encode(input_data))
84
+ expect = np.array(input_data, dtype=dtype)
85
+ assert expect.shape == actual.shape
86
+ assert np.array_equal(expect, actual)
87
+
88
+
89
+ def test_encode_decode_shape_dtype_preserved():
90
+ codec = MsgPack()
91
+ for arr in arrays:
92
+ actual = codec.decode(codec.encode(arr))
93
+ assert arr.shape == actual.shape
94
+ assert arr.dtype == actual.dtype
95
+
96
+
97
+ def test_bytes():
98
+ # test msgpack behaviour with bytes and str (unicode)
99
+ bytes_arr = np.array([b'foo', b'bar', b'baz'], dtype=object)
100
+ unicode_arr = np.array(['foo', 'bar', 'baz'], dtype=object)
101
+
102
+ # raw=False (default)
103
+ codec = MsgPack()
104
+ # works for bytes array, round-trips bytes to bytes
105
+ b = codec.decode(codec.encode(bytes_arr))
106
+ assert np.array_equal(bytes_arr, b)
107
+ assert isinstance(b[0], bytes)
108
+ assert b[0] == b'foo'
109
+ # works for unicode array, round-trips unicode to unicode
110
+ b = codec.decode(codec.encode(unicode_arr))
111
+ assert np.array_equal(unicode_arr, b)
112
+ assert isinstance(b[0], str)
113
+ assert b[0] == 'foo'
114
+
115
+ # raw=True
116
+ codec = MsgPack(raw=True)
117
+ # works for bytes array, round-trips bytes to bytes
118
+ b = codec.decode(codec.encode(bytes_arr))
119
+ assert np.array_equal(bytes_arr, b)
120
+ assert isinstance(b[0], bytes)
121
+ assert b[0] == b'foo'
122
+ # broken for unicode array, round-trips unicode to bytes
123
+ b = codec.decode(codec.encode(unicode_arr))
124
+ assert not np.array_equal(unicode_arr, b)
125
+ assert isinstance(b[0], bytes)
126
+ assert b[0] == b'foo'
@@ -0,0 +1,48 @@
1
+ import pytest
2
+
3
+ from numcodecs.ndarray_like import DType, FlagsObj, NDArrayLike
4
+
5
+
6
+ @pytest.mark.parametrize("module", ["numpy", "cupy"])
7
+ def test_is_ndarray_like(module):
8
+ m = pytest.importorskip(module)
9
+ a = m.arange(10)
10
+ assert isinstance(a, NDArrayLike)
11
+
12
+
13
+ def test_is_not_ndarray_like():
14
+ assert not isinstance([1, 2, 3], NDArrayLike)
15
+ assert not isinstance(b"1,2,3", NDArrayLike)
16
+
17
+
18
+ @pytest.mark.parametrize("module", ["numpy", "cupy"])
19
+ def test_is_dtype_like(module):
20
+ m = pytest.importorskip(module)
21
+ d = m.dtype("u8")
22
+ assert isinstance(d, DType)
23
+
24
+
25
+ def test_is_not_dtype_like():
26
+ assert not isinstance([1, 2, 3], DType)
27
+ assert not isinstance(b"1,2,3", DType)
28
+
29
+
30
+ @pytest.mark.parametrize("module", ["numpy", "cupy"])
31
+ def test_is_flags_like(module):
32
+ m = pytest.importorskip(module)
33
+ d = m.arange(10).flags
34
+ assert isinstance(d, FlagsObj)
35
+
36
+
37
+ def test_is_not_flags_like():
38
+ assert not isinstance([1, 2, 3], FlagsObj)
39
+ assert not isinstance(b"1,2,3", FlagsObj)
40
+
41
+
42
+ @pytest.mark.parametrize("module", ["numpy", "cupy"])
43
+ def test_cached_isinstance_check(module):
44
+ m = pytest.importorskip(module)
45
+ a = m.arange(10)
46
+ assert isinstance(a, NDArrayLike)
47
+ assert not isinstance(a, DType)
48
+ assert not isinstance(a, FlagsObj)
@@ -0,0 +1,39 @@
1
+ import numpy as np
2
+
3
+ from numcodecs.packbits import PackBits
4
+ from numcodecs.tests.common import (
5
+ check_backwards_compatibility,
6
+ check_config,
7
+ check_encode_decode,
8
+ check_repr,
9
+ )
10
+
11
+ arrays = [
12
+ np.random.randint(0, 2, size=1000, dtype=bool),
13
+ np.random.randint(0, 2, size=(100, 10), dtype=bool),
14
+ np.random.randint(0, 2, size=(10, 10, 10), dtype=bool),
15
+ np.random.randint(0, 2, size=1000, dtype=bool).reshape(10, 10, 10, order='F'),
16
+ ]
17
+
18
+
19
+ def test_encode_decode():
20
+ codec = PackBits()
21
+ for arr in arrays:
22
+ check_encode_decode(arr, codec)
23
+ # check different number of left-over bits
24
+ arr = np.random.randint(0, 2, size=1000, dtype=bool)
25
+ for size in list(range(1, 17)):
26
+ check_encode_decode(arr[:size], codec)
27
+
28
+
29
+ def test_config():
30
+ codec = PackBits()
31
+ check_config(codec)
32
+
33
+
34
+ def test_repr():
35
+ check_repr("PackBits()")
36
+
37
+
38
+ def test_backwards_compatibility():
39
+ check_backwards_compatibility(PackBits.codec_id, arrays, [PackBits()])
@@ -0,0 +1,90 @@
1
+ import numpy as np
2
+ import pytest
3
+
4
+ try:
5
+ from numcodecs.pcodec import PCodec
6
+ except ImportError: # pragma: no cover
7
+ pytest.skip("pcodec not available", allow_module_level=True)
8
+
9
+ from numcodecs.tests.common import (
10
+ check_backwards_compatibility,
11
+ check_config,
12
+ check_encode_decode_array,
13
+ check_err_decode_object_buffer,
14
+ check_err_encode_object_buffer,
15
+ check_repr,
16
+ )
17
+
18
+ codecs = [
19
+ PCodec(),
20
+ PCodec(level=1),
21
+ PCodec(level=5),
22
+ PCodec(level=9),
23
+ PCodec(mode_spec="classic"),
24
+ PCodec(equal_pages_up_to=300),
25
+ PCodec(delta_encoding_order=2),
26
+ PCodec(delta_spec="try_lookback"),
27
+ PCodec(delta_spec="none"),
28
+ PCodec(delta_spec="try_consecutive", delta_encoding_order=1),
29
+ ]
30
+
31
+
32
+ # mix of dtypes: integer, float
33
+ # mix of shapes: 1D, 2D
34
+ # mix of orders: C, F
35
+ arrays = [
36
+ np.arange(1000, dtype="u4"),
37
+ np.arange(1000, dtype="u8"),
38
+ np.arange(1000, dtype="i4"),
39
+ np.arange(1000, dtype="i8"),
40
+ np.linspace(1000, 1001, 1000, dtype="f4"),
41
+ np.linspace(1000, 1001, 1000, dtype="f8"),
42
+ np.random.normal(loc=1000, scale=1, size=(100, 10)),
43
+ np.asfortranarray(np.random.normal(loc=1000, scale=1, size=(100, 10))),
44
+ np.random.randint(0, 2**60, size=1000, dtype="u8"),
45
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8"),
46
+ ]
47
+
48
+
49
+ @pytest.mark.parametrize("arr", arrays)
50
+ @pytest.mark.parametrize("codec", codecs)
51
+ def test_encode_decode(arr, codec):
52
+ check_encode_decode_array(arr, codec)
53
+
54
+
55
+ def test_config():
56
+ codec = PCodec(level=3)
57
+ check_config(codec)
58
+
59
+
60
+ @pytest.mark.parametrize("param", ["mode_spec", "delta_spec", "paging_spec"])
61
+ def test_invalid_config_error(param):
62
+ codec = PCodec(**{param: "bogus"})
63
+ with pytest.raises(ValueError):
64
+ check_encode_decode_array(arrays[0], codec)
65
+
66
+
67
+ def test_invalid_delta_encoding_combo():
68
+ codec = PCodec(delta_encoding_order=2, delta_spec="none")
69
+ with pytest.raises(ValueError):
70
+ check_encode_decode_array(arrays[0], codec)
71
+
72
+
73
+ def test_repr():
74
+ check_repr(
75
+ "PCodec(delta_encoding_order=None, delta_spec='auto',"
76
+ " equal_pages_up_to=262144, level=3, mode_spec='auto',"
77
+ " paging_spec='equal_pages_up_to')"
78
+ )
79
+
80
+
81
+ def test_backwards_compatibility():
82
+ check_backwards_compatibility(PCodec.codec_id, arrays, codecs)
83
+
84
+
85
+ def test_err_decode_object_buffer():
86
+ check_err_decode_object_buffer(PCodec())
87
+
88
+
89
+ def test_err_encode_object_buffer():
90
+ check_err_encode_object_buffer(PCodec())
@@ -0,0 +1,61 @@
1
+ import itertools
2
+ import sys
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ from numcodecs.pickles import Pickle
8
+ from numcodecs.tests.common import (
9
+ check_backwards_compatibility,
10
+ check_config,
11
+ check_encode_decode_array,
12
+ check_repr,
13
+ greetings,
14
+ )
15
+
16
+ codecs = [Pickle(protocol=i) for i in range(5)]
17
+
18
+ # object array with strings
19
+ # object array with mix strings / nans
20
+ # object array with mix of string, int, float
21
+ # ...
22
+ arrays = [
23
+ np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
24
+ np.array([['foo', 'bar', np.nan]] * 300, dtype=object),
25
+ np.array(['foo', 1.0, 2] * 300, dtype=object),
26
+ np.arange(1000, dtype='i4'),
27
+ np.array(['foo', 'bar', 'baz'] * 300),
28
+ np.array(['foo', ['bar', 1.0, 2], {'a': 'b', 'c': 42}] * 300, dtype=object),
29
+ np.array(greetings * 100),
30
+ np.array(greetings * 100, dtype=object),
31
+ ]
32
+
33
+
34
+ def test_encode_decode():
35
+ for arr, codec in itertools.product(arrays, codecs):
36
+ check_encode_decode_array(arr, codec)
37
+
38
+
39
+ def test_config():
40
+ codec = Pickle(protocol=-1)
41
+ check_config(codec)
42
+ for codec in codecs:
43
+ check_config(codec)
44
+
45
+
46
+ def test_repr():
47
+ check_repr("Pickle(protocol=-1)")
48
+
49
+
50
+ # Details on xfail
51
+ # https://stackoverflow.com/questions/58194852/modulenotfounderror-no-module-named-numpy-core-multiarray-r
52
+ @pytest.mark.skipif(sys.byteorder != "little", reason="Pickle does not restore byte orders")
53
+ @pytest.mark.xfail(
54
+ sys.platform == "win32",
55
+ reason=(
56
+ "Pickle fails to read w/ Windows carriage return "
57
+ "( https://github.com/zarr-developers/numcodecs/issues/271 )"
58
+ ),
59
+ )
60
+ def test_backwards_compatibility():
61
+ check_backwards_compatibility(Pickle.codec_id, arrays, codecs)