numcodecs 0.16.0__cp311-cp311-macosx_10_13_x86_64.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-311-darwin.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-311-darwin.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-311-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-311-darwin.so +0 -0
  17. numcodecs/gzip.py +50 -0
  18. numcodecs/jenkins.cpython-311-darwin.so +0 -0
  19. numcodecs/json.py +107 -0
  20. numcodecs/lz4.cpython-311-darwin.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-311-darwin.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-311-darwin.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,166 @@
1
+ from multiprocessing import Pool
2
+ from multiprocessing.pool import ThreadPool
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ try:
8
+ from numcodecs.shuffle import Shuffle
9
+ except ImportError: # pragma: no cover
10
+ pytest.skip("numcodecs.shuffle not available", allow_module_level=True)
11
+
12
+
13
+ from numcodecs.tests.common import (
14
+ check_backwards_compatibility,
15
+ check_config,
16
+ check_encode_decode,
17
+ )
18
+
19
+ codecs = [
20
+ Shuffle(),
21
+ Shuffle(elementsize=0),
22
+ Shuffle(elementsize=4),
23
+ Shuffle(elementsize=8),
24
+ ]
25
+
26
+
27
+ # mix of dtypes: integer, float, bool, string
28
+ # mix of shapes: 1D, 2D, 3D
29
+ # mix of orders: C, F
30
+ arrays = [
31
+ np.arange(1000, dtype='i4'),
32
+ np.linspace(1000, 1001, 1000, dtype='f8'),
33
+ np.random.normal(loc=1000, scale=1, size=(100, 10)),
34
+ np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
35
+ np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
36
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('M8[ns]'),
37
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
38
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
39
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
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[ns]'),
42
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
43
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
44
+ ]
45
+
46
+
47
+ @pytest.mark.parametrize('array', arrays)
48
+ @pytest.mark.parametrize('codec', codecs)
49
+ def test_encode_decode(array, codec):
50
+ check_encode_decode(array, codec)
51
+
52
+
53
+ def test_config():
54
+ codec = Shuffle()
55
+ check_config(codec)
56
+ codec = Shuffle(elementsize=8)
57
+ check_config(codec)
58
+
59
+
60
+ def test_repr():
61
+ expect = "Shuffle(elementsize=0)"
62
+ actual = repr(Shuffle(elementsize=0))
63
+ assert expect == actual
64
+ expect = "Shuffle(elementsize=4)"
65
+ actual = repr(Shuffle(elementsize=4))
66
+ assert expect == actual
67
+ expect = "Shuffle(elementsize=8)"
68
+ actual = repr(Shuffle(elementsize=8))
69
+ assert expect == actual
70
+ expect = "Shuffle(elementsize=16)"
71
+ actual = repr(Shuffle(elementsize=16))
72
+ assert expect == actual
73
+
74
+
75
+ def test_eq():
76
+ assert Shuffle() == Shuffle()
77
+ assert Shuffle(elementsize=16) != Shuffle()
78
+
79
+
80
+ def _encode_worker(data):
81
+ compressor = Shuffle()
82
+ return compressor.encode(data)
83
+
84
+
85
+ def _decode_worker(enc):
86
+ compressor = Shuffle()
87
+ return compressor.decode(enc)
88
+
89
+
90
+ @pytest.mark.parametrize('pool', [Pool, ThreadPool])
91
+ def test_multiprocessing(pool):
92
+ data = np.arange(1000000)
93
+ enc = _encode_worker(data)
94
+
95
+ pool = pool(5)
96
+
97
+ # test with process pool and thread pool
98
+
99
+ # test encoding
100
+ enc_results = pool.map(_encode_worker, [data] * 5)
101
+ assert all(len(enc) == len(e) for e in enc_results)
102
+
103
+ # test decoding
104
+ dec_results = pool.map(_decode_worker, [enc] * 5)
105
+ assert all(data.nbytes == len(d) for d in dec_results)
106
+
107
+ # tidy up
108
+ pool.close()
109
+ pool.join()
110
+
111
+
112
+ def test_backwards_compatibility():
113
+ check_backwards_compatibility(Shuffle.codec_id, arrays, codecs)
114
+
115
+
116
+ # def test_err_decode_object_buffer():
117
+ # check_err_decode_object_buffer(Shuffle())
118
+
119
+
120
+ # def test_err_encode_object_buffer():
121
+ # check_err_encode_object_buffer(Shuffle())
122
+
123
+ # def test_decompression_error_handling():
124
+ # for codec in codecs:
125
+ # with pytest.raises(RuntimeError):
126
+ # codec.decode(bytearray())
127
+ # with pytest.raises(RuntimeError):
128
+ # codec.decode(bytearray(0))
129
+
130
+
131
+ def test_expected_result():
132
+ # If the input is treated as a 2D byte array, with shape (size of element, number of elements),
133
+ # the shuffle is essentially a transpose. This can be made more apparent by using an array of
134
+ # big-endian integers, as below.
135
+ arr = np.array(
136
+ [
137
+ 0x0001020304050607,
138
+ 0x08090A0B0C0D0E0F,
139
+ 0x1011121314151617,
140
+ 0x18191A1B1C1D1E1F,
141
+ ],
142
+ dtype='>u8',
143
+ )
144
+ expected = np.array(
145
+ [
146
+ 0x00081018,
147
+ 0x01091119,
148
+ 0x020A121A,
149
+ 0x030B131B,
150
+ 0x040C141C,
151
+ 0x050D151D,
152
+ 0x060E161E,
153
+ 0x070F171F,
154
+ ],
155
+ dtype='u4',
156
+ )
157
+ codec = Shuffle(elementsize=arr.data.itemsize)
158
+ enc = codec.encode(arr)
159
+ np.testing.assert_array_equal(np.frombuffer(enc.data, '>u4'), expected)
160
+
161
+
162
+ def test_incompatible_elementsize():
163
+ arr = np.arange(1001, dtype='u1')
164
+ codec = Shuffle(elementsize=4)
165
+ with pytest.raises(ValueError):
166
+ codec.encode(arr)
@@ -0,0 +1,97 @@
1
+ import unittest
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ try:
7
+ from numcodecs.vlen import VLenArray
8
+ except ImportError as e: # pragma: no cover
9
+ raise unittest.SkipTest("vlen-array not available") from e
10
+ from numcodecs.tests.common import (
11
+ assert_array_items_equal,
12
+ check_backwards_compatibility,
13
+ check_config,
14
+ check_encode_decode_array,
15
+ check_repr,
16
+ )
17
+
18
+ arrays = [
19
+ np.array([np.array([1, 2, 3]), np.array([4]), np.array([5, 6])] * 300, dtype=object),
20
+ np.array([np.array([1, 2, 3]), np.array([4]), np.array([5, 6])] * 300, dtype=object).reshape(
21
+ 90, 10
22
+ ),
23
+ ]
24
+
25
+
26
+ codecs = [
27
+ VLenArray('<i1'),
28
+ VLenArray('<i2'),
29
+ VLenArray('<i4'),
30
+ VLenArray('<i8'),
31
+ VLenArray('<u1'),
32
+ VLenArray('<u2'),
33
+ VLenArray('<u4'),
34
+ VLenArray('<u8'),
35
+ ]
36
+
37
+
38
+ def test_encode_decode():
39
+ for arr in arrays:
40
+ for codec in codecs:
41
+ check_encode_decode_array(arr, codec)
42
+
43
+
44
+ def test_config():
45
+ codec = VLenArray('<i8')
46
+ check_config(codec)
47
+
48
+
49
+ def test_repr():
50
+ check_repr("VLenArray(dtype='<i8')")
51
+
52
+
53
+ def test_backwards_compatibility():
54
+ check_backwards_compatibility(VLenArray.codec_id, arrays, codecs)
55
+
56
+
57
+ def test_encode_errors():
58
+ codec = VLenArray('<i8')
59
+ with pytest.raises(ValueError):
60
+ codec.encode('foo')
61
+ with pytest.raises(ValueError):
62
+ codec.encode(['foo', 'bar'])
63
+
64
+
65
+ def test_decode_errors():
66
+ codec = VLenArray('<i8')
67
+ with pytest.raises(TypeError):
68
+ codec.decode(1234)
69
+ # these should look like corrupt data
70
+ with pytest.raises(ValueError):
71
+ codec.decode(b'foo')
72
+ with pytest.raises(ValueError):
73
+ codec.decode(np.arange(2, 3, dtype='i4'))
74
+ with pytest.raises(ValueError):
75
+ codec.decode(np.arange(10, 20, dtype='i4'))
76
+ with pytest.raises(TypeError):
77
+ codec.decode('foo')
78
+
79
+ # test out parameter
80
+ enc = codec.encode(arrays[0])
81
+ with pytest.raises(TypeError):
82
+ codec.decode(enc, out=b'foo')
83
+ with pytest.raises(TypeError):
84
+ codec.decode(enc, out='foo')
85
+ with pytest.raises(TypeError):
86
+ codec.decode(enc, out=123)
87
+ with pytest.raises(ValueError):
88
+ codec.decode(enc, out=np.zeros(10, dtype='i4'))
89
+
90
+
91
+ def test_encode_none():
92
+ a = np.array([[1, 3], None, [4, 7]], dtype=object)
93
+ codec = VLenArray(int)
94
+ enc = codec.encode(a)
95
+ dec = codec.decode(enc)
96
+ expect = np.array([np.array([1, 3]), np.array([]), np.array([4, 7])], dtype=object)
97
+ assert_array_items_equal(expect, dec)
@@ -0,0 +1,97 @@
1
+ import sys
2
+ import unittest
3
+
4
+ import numpy as np
5
+ import pytest
6
+
7
+ try:
8
+ from numcodecs.vlen import VLenBytes
9
+ except ImportError as e: # pragma: no cover
10
+ raise unittest.SkipTest("vlen-bytes not available") from e
11
+ from numcodecs.tests.common import (
12
+ assert_array_items_equal,
13
+ check_backwards_compatibility,
14
+ check_config,
15
+ check_encode_decode_array,
16
+ check_repr,
17
+ greetings,
18
+ )
19
+
20
+ greetings_bytes = [g.encode('utf-8') for g in greetings]
21
+
22
+
23
+ arrays = [
24
+ np.array([b'foo', b'bar', b'baz'] * 300, dtype=object),
25
+ np.array(greetings_bytes * 100, dtype=object),
26
+ np.array([b'foo', b'bar', b'baz'] * 300, dtype=object).reshape(90, 10),
27
+ np.array(greetings_bytes * 1000, dtype=object).reshape(
28
+ len(greetings_bytes), 100, 10, order='F'
29
+ ),
30
+ ]
31
+
32
+
33
+ def test_encode_decode():
34
+ for arr in arrays:
35
+ codec = VLenBytes()
36
+ check_encode_decode_array(arr, codec)
37
+
38
+
39
+ def test_config():
40
+ codec = VLenBytes()
41
+ check_config(codec)
42
+
43
+
44
+ def test_repr():
45
+ check_repr("VLenBytes()")
46
+
47
+
48
+ def test_backwards_compatibility():
49
+ check_backwards_compatibility(VLenBytes.codec_id, arrays, [VLenBytes()])
50
+
51
+
52
+ def test_encode_errors():
53
+ codec = VLenBytes()
54
+ with pytest.raises(TypeError):
55
+ codec.encode(1234)
56
+ with pytest.raises(TypeError):
57
+ codec.encode([1234, 5678])
58
+ with pytest.raises(TypeError):
59
+ codec.encode(np.ones(10, dtype='i4'))
60
+
61
+
62
+ def test_decode_errors():
63
+ codec = VLenBytes()
64
+ with pytest.raises(TypeError):
65
+ codec.decode(1234)
66
+ # these should look like corrupt data
67
+ with pytest.raises(ValueError):
68
+ codec.decode(b'foo')
69
+ with pytest.raises(ValueError):
70
+ codec.decode(np.arange(2, 3, dtype='i4'))
71
+ with pytest.raises(ValueError):
72
+ codec.decode(np.arange(10, 20, dtype='i4'))
73
+ with pytest.raises(TypeError):
74
+ codec.decode('foo')
75
+
76
+ # test out parameter
77
+ enc = codec.encode(arrays[0])
78
+ with pytest.raises(TypeError):
79
+ codec.decode(enc, out=b'foo')
80
+ with pytest.raises(TypeError):
81
+ codec.decode(enc, out='foo')
82
+ with pytest.raises(TypeError):
83
+ codec.decode(enc, out=123)
84
+ with pytest.raises(ValueError):
85
+ codec.decode(enc, out=np.zeros(10, dtype='i4'))
86
+
87
+
88
+ # TODO: fix this test on GitHub actions somehow...
89
+ # See https://github.com/zarr-developers/numcodecs/issues/683
90
+ @pytest.mark.skipif(sys.platform == "darwin", reason="Test is failing on macOS on GitHub actions.")
91
+ def test_encode_none():
92
+ a = np.array([b'foo', None, b'bar'], dtype=object)
93
+ codec = VLenBytes()
94
+ enc = codec.encode(a)
95
+ dec = codec.decode(enc)
96
+ expect = np.array([b'foo', b'', b'bar'], dtype=object)
97
+ assert_array_items_equal(expect, dec)
@@ -0,0 +1,91 @@
1
+ import unittest
2
+
3
+ import numpy as np
4
+ import pytest
5
+
6
+ try:
7
+ from numcodecs.vlen import VLenUTF8
8
+ except ImportError as e: # pragma: no cover
9
+ raise unittest.SkipTest("vlen-utf8 not available") from e
10
+ from numcodecs.tests.common import (
11
+ assert_array_items_equal,
12
+ check_backwards_compatibility,
13
+ check_config,
14
+ check_encode_decode_array,
15
+ check_repr,
16
+ greetings,
17
+ )
18
+
19
+ arrays = [
20
+ np.array(['foo', 'bar', 'baz'] * 300, dtype=object),
21
+ np.array(greetings * 100, dtype=object),
22
+ np.array(['foo', 'bar', 'baz'] * 300, dtype=object).reshape(90, 10),
23
+ np.array(greetings * 1000, dtype=object).reshape(len(greetings), 100, 10, order='F'),
24
+ ]
25
+
26
+
27
+ def test_encode_decode():
28
+ for arr in arrays:
29
+ codec = VLenUTF8()
30
+ check_encode_decode_array(arr, codec)
31
+
32
+
33
+ def test_config():
34
+ codec = VLenUTF8()
35
+ check_config(codec)
36
+
37
+
38
+ def test_repr():
39
+ check_repr("VLenUTF8()")
40
+
41
+
42
+ def test_backwards_compatibility():
43
+ check_backwards_compatibility(VLenUTF8.codec_id, arrays, [VLenUTF8()])
44
+
45
+
46
+ def test_encode_errors():
47
+ codec = VLenUTF8()
48
+ with pytest.raises(TypeError):
49
+ codec.encode(1234)
50
+ with pytest.raises(TypeError):
51
+ codec.encode([1234, 5678])
52
+ with pytest.raises(TypeError):
53
+ codec.encode(np.ones(10, dtype='i4'))
54
+
55
+
56
+ def test_decode_errors():
57
+ codec = VLenUTF8()
58
+ with pytest.raises(TypeError):
59
+ codec.decode(1234)
60
+ # these should look like corrupt data
61
+ with pytest.raises(ValueError):
62
+ codec.decode(b'foo')
63
+ with pytest.raises(ValueError):
64
+ codec.decode(np.arange(2, 3, dtype='i4'))
65
+ with pytest.raises(ValueError):
66
+ codec.decode(np.arange(10, 20, dtype='i4'))
67
+ with pytest.raises(TypeError):
68
+ codec.decode('foo')
69
+
70
+ # test out parameter
71
+ enc = codec.encode(arrays[0])
72
+ with pytest.raises(TypeError):
73
+ codec.decode(enc, out=b'foo')
74
+ with pytest.raises(TypeError):
75
+ codec.decode(enc, out='foo')
76
+ with pytest.raises(TypeError):
77
+ codec.decode(enc, out=123)
78
+ with pytest.raises(ValueError):
79
+ codec.decode(enc, out=np.zeros(10, dtype='i4'))
80
+
81
+
82
+ @pytest.mark.parametrize("writable", [True, False])
83
+ def test_encode_utf8(writable):
84
+ a = np.array(['foo', None, 'bar'], dtype=object)
85
+ if not writable:
86
+ a.setflags(write=False)
87
+ codec = VLenUTF8()
88
+ enc = codec.encode(a)
89
+ dec = codec.decode(enc)
90
+ expect = np.array(['foo', '', 'bar'], dtype=object)
91
+ assert_array_items_equal(expect, dec)