numcodecs 0.13.1__cp313-cp313-win_amd64.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.
- numcodecs/__init__.py +143 -0
- numcodecs/_shuffle.cp313-win_amd64.pyd +0 -0
- numcodecs/abc.py +126 -0
- numcodecs/astype.py +76 -0
- numcodecs/base64.py +27 -0
- numcodecs/bitround.py +79 -0
- numcodecs/blosc.cp313-win_amd64.pyd +0 -0
- numcodecs/bz2.py +45 -0
- numcodecs/categorize.py +101 -0
- numcodecs/checksum32.py +94 -0
- numcodecs/compat.py +208 -0
- numcodecs/compat_ext.cp313-win_amd64.pyd +0 -0
- numcodecs/delta.py +97 -0
- numcodecs/fixedscaleoffset.py +132 -0
- numcodecs/fletcher32.cp313-win_amd64.pyd +0 -0
- numcodecs/gzip.py +52 -0
- numcodecs/jenkins.cp313-win_amd64.pyd +0 -0
- numcodecs/json.py +107 -0
- numcodecs/lz4.cp313-win_amd64.pyd +0 -0
- numcodecs/lzma.py +69 -0
- numcodecs/msgpacks.py +86 -0
- numcodecs/ndarray_like.py +65 -0
- numcodecs/packbits.py +85 -0
- numcodecs/pcodec.py +89 -0
- numcodecs/pickles.py +55 -0
- numcodecs/quantize.py +100 -0
- numcodecs/registry.py +72 -0
- numcodecs/shuffle.py +61 -0
- numcodecs/tests/__init__.py +3 -0
- numcodecs/tests/common.py +354 -0
- numcodecs/tests/package_with_entrypoint/__init__.py +11 -0
- numcodecs/tests/package_with_entrypoint-0.1.dist-info/entry_points.txt +2 -0
- numcodecs/tests/test_astype.py +74 -0
- numcodecs/tests/test_base64.py +81 -0
- numcodecs/tests/test_bitround.py +81 -0
- numcodecs/tests/test_blosc.py +277 -0
- numcodecs/tests/test_bz2.py +66 -0
- numcodecs/tests/test_categorize.py +87 -0
- numcodecs/tests/test_checksum32.py +58 -0
- numcodecs/tests/test_compat.py +108 -0
- numcodecs/tests/test_delta.py +60 -0
- numcodecs/tests/test_entrypoints.py +24 -0
- numcodecs/tests/test_entrypoints_backport.py +35 -0
- numcodecs/tests/test_fixedscaleoffset.py +69 -0
- numcodecs/tests/test_fletcher32.py +56 -0
- numcodecs/tests/test_gzip.py +110 -0
- numcodecs/tests/test_jenkins.py +150 -0
- numcodecs/tests/test_json.py +85 -0
- numcodecs/tests/test_lz4.py +83 -0
- numcodecs/tests/test_lzma.py +90 -0
- numcodecs/tests/test_msgpacks.py +123 -0
- numcodecs/tests/test_ndarray_like.py +48 -0
- numcodecs/tests/test_packbits.py +39 -0
- numcodecs/tests/test_pcodec.py +80 -0
- numcodecs/tests/test_pickles.py +61 -0
- numcodecs/tests/test_quantize.py +76 -0
- numcodecs/tests/test_registry.py +40 -0
- numcodecs/tests/test_shuffle.py +168 -0
- numcodecs/tests/test_vlen_array.py +97 -0
- numcodecs/tests/test_vlen_bytes.py +93 -0
- numcodecs/tests/test_vlen_utf8.py +91 -0
- numcodecs/tests/test_zfpy.py +98 -0
- numcodecs/tests/test_zlib.py +94 -0
- numcodecs/tests/test_zstd.py +92 -0
- numcodecs/version.py +16 -0
- numcodecs/vlen.cp313-win_amd64.pyd +0 -0
- numcodecs/zfpy.py +111 -0
- numcodecs/zlib.py +42 -0
- numcodecs/zstd.cp313-win_amd64.pyd +0 -0
- numcodecs-0.13.1.dist-info/LICENSE.txt +21 -0
- numcodecs-0.13.1.dist-info/METADATA +64 -0
- numcodecs-0.13.1.dist-info/RECORD +74 -0
- numcodecs-0.13.1.dist-info/WHEEL +5 -0
- numcodecs-0.13.1.dist-info/top_level.txt +1 -0
|
@@ -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,93 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from numcodecs.vlen import VLenBytes
|
|
8
|
+
except ImportError as e: # pragma: no cover
|
|
9
|
+
raise unittest.SkipTest("vlen-bytes 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
|
+
greetings_bytes = [g.encode('utf-8') for g in greetings]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
arrays = [
|
|
23
|
+
np.array([b'foo', b'bar', b'baz'] * 300, dtype=object),
|
|
24
|
+
np.array(greetings_bytes * 100, dtype=object),
|
|
25
|
+
np.array([b'foo', b'bar', b'baz'] * 300, dtype=object).reshape(90, 10),
|
|
26
|
+
np.array(greetings_bytes * 1000, dtype=object).reshape(
|
|
27
|
+
len(greetings_bytes), 100, 10, order='F'
|
|
28
|
+
),
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_encode_decode():
|
|
33
|
+
for arr in arrays:
|
|
34
|
+
codec = VLenBytes()
|
|
35
|
+
check_encode_decode_array(arr, codec)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_config():
|
|
39
|
+
codec = VLenBytes()
|
|
40
|
+
check_config(codec)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_repr():
|
|
44
|
+
check_repr("VLenBytes()")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_backwards_compatibility():
|
|
48
|
+
check_backwards_compatibility(VLenBytes.codec_id, arrays, [VLenBytes()])
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_encode_errors():
|
|
52
|
+
codec = VLenBytes()
|
|
53
|
+
with pytest.raises(TypeError):
|
|
54
|
+
codec.encode(1234)
|
|
55
|
+
with pytest.raises(TypeError):
|
|
56
|
+
codec.encode([1234, 5678])
|
|
57
|
+
with pytest.raises(TypeError):
|
|
58
|
+
codec.encode(np.ones(10, dtype='i4'))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_decode_errors():
|
|
62
|
+
codec = VLenBytes()
|
|
63
|
+
with pytest.raises(TypeError):
|
|
64
|
+
codec.decode(1234)
|
|
65
|
+
# these should look like corrupt data
|
|
66
|
+
with pytest.raises(ValueError):
|
|
67
|
+
codec.decode(b'foo')
|
|
68
|
+
with pytest.raises(ValueError):
|
|
69
|
+
codec.decode(np.arange(2, 3, dtype='i4'))
|
|
70
|
+
with pytest.raises(ValueError):
|
|
71
|
+
codec.decode(np.arange(10, 20, dtype='i4'))
|
|
72
|
+
with pytest.raises(TypeError):
|
|
73
|
+
codec.decode('foo')
|
|
74
|
+
|
|
75
|
+
# test out parameter
|
|
76
|
+
enc = codec.encode(arrays[0])
|
|
77
|
+
with pytest.raises(TypeError):
|
|
78
|
+
codec.decode(enc, out=b'foo')
|
|
79
|
+
with pytest.raises(TypeError):
|
|
80
|
+
codec.decode(enc, out='foo')
|
|
81
|
+
with pytest.raises(TypeError):
|
|
82
|
+
codec.decode(enc, out=123)
|
|
83
|
+
with pytest.raises(ValueError):
|
|
84
|
+
codec.decode(enc, out=np.zeros(10, dtype='i4'))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_encode_none():
|
|
88
|
+
a = np.array([b'foo', None, b'bar'], dtype=object)
|
|
89
|
+
codec = VLenBytes()
|
|
90
|
+
enc = codec.encode(a)
|
|
91
|
+
dec = codec.decode(enc)
|
|
92
|
+
expect = np.array([b'foo', b'', b'bar'], dtype=object)
|
|
93
|
+
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)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
# noinspection PyProtectedMember
|
|
6
|
+
from numcodecs.zfpy import ZFPY, _zfpy
|
|
7
|
+
except ImportError: # pragma: no cover
|
|
8
|
+
pytest.skip("ZFPY not available", allow_module_level=True)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
from numcodecs.tests.common import (
|
|
12
|
+
check_backwards_compatibility,
|
|
13
|
+
check_config,
|
|
14
|
+
check_encode_decode_array,
|
|
15
|
+
check_err_decode_object_buffer,
|
|
16
|
+
check_err_encode_object_buffer,
|
|
17
|
+
check_repr,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
codecs = [
|
|
21
|
+
ZFPY(mode=_zfpy.mode_fixed_rate, rate=-1),
|
|
22
|
+
ZFPY(),
|
|
23
|
+
ZFPY(mode=_zfpy.mode_fixed_accuracy, tolerance=-1),
|
|
24
|
+
ZFPY(mode=_zfpy.mode_fixed_precision, precision=-1),
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# mix of dtypes: integer, float, bool, string
|
|
29
|
+
# mix of shapes: 1D, 2D, 3D
|
|
30
|
+
# mix of orders: C, F
|
|
31
|
+
arrays = [
|
|
32
|
+
np.linspace(1000, 1001, 1000, dtype="f4"),
|
|
33
|
+
np.linspace(1000, 1001, 1000, dtype="f8"),
|
|
34
|
+
np.random.normal(loc=1000, scale=1, size=(100, 10)),
|
|
35
|
+
np.random.normal(loc=1000, scale=1, size=(10, 10, 10)),
|
|
36
|
+
np.random.normal(loc=1000, scale=1, size=(2, 5, 10, 10)),
|
|
37
|
+
np.random.randint(-(2**31), -(2**31) + 20, size=1000, dtype="i4").reshape(100, 10),
|
|
38
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").reshape(10, 10, 10),
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_encode_decode():
|
|
43
|
+
for arr in arrays:
|
|
44
|
+
if arr.dtype in (np.int32, np.int64):
|
|
45
|
+
codec = [codecs[-1]]
|
|
46
|
+
else:
|
|
47
|
+
codec = codecs
|
|
48
|
+
for code in codec:
|
|
49
|
+
check_encode_decode_array(arr, code)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_config():
|
|
53
|
+
for codec in codecs:
|
|
54
|
+
check_config(codec)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_repr():
|
|
58
|
+
check_repr("ZFPY(mode=4, tolerance=0.001, rate=-1, precision=-1)")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_backwards_compatibility():
|
|
62
|
+
for code in codecs:
|
|
63
|
+
if code.mode == _zfpy.mode_fixed_rate:
|
|
64
|
+
codec = [code]
|
|
65
|
+
check_backwards_compatibility(ZFPY.codec_id, arrays, codec)
|
|
66
|
+
else:
|
|
67
|
+
check_backwards_compatibility(ZFPY.codec_id, arrays[: len(arrays) - 2], codecs)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_err_decode_object_buffer():
|
|
71
|
+
check_err_decode_object_buffer(ZFPY())
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_err_encode_object_buffer():
|
|
75
|
+
check_err_encode_object_buffer(ZFPY())
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_err_encode_list():
|
|
79
|
+
data = ['foo', 'bar', 'baz']
|
|
80
|
+
for codec in codecs:
|
|
81
|
+
with pytest.raises(TypeError):
|
|
82
|
+
codec.encode(data)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_err_encode_non_contiguous():
|
|
86
|
+
# non-contiguous memory
|
|
87
|
+
arr = np.arange(1000, dtype='i4')[::2]
|
|
88
|
+
for codec in codecs:
|
|
89
|
+
with pytest.raises(ValueError):
|
|
90
|
+
codec.encode(arr)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def test_err_encode_fortran_array():
|
|
94
|
+
# fortran array
|
|
95
|
+
arr = np.asfortranarray(np.random.normal(loc=1000, scale=1, size=(5, 10, 20)))
|
|
96
|
+
for codec in codecs:
|
|
97
|
+
with pytest.raises(ValueError):
|
|
98
|
+
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,16 @@
|
|
|
1
|
+
# file generated by setuptools_scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
TYPE_CHECKING = False
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from typing import Tuple, Union
|
|
6
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
7
|
+
else:
|
|
8
|
+
VERSION_TUPLE = object
|
|
9
|
+
|
|
10
|
+
version: str
|
|
11
|
+
__version__: str
|
|
12
|
+
__version_tuple__: VERSION_TUPLE
|
|
13
|
+
version_tuple: VERSION_TUPLE
|
|
14
|
+
|
|
15
|
+
__version__ = version = '0.13.1'
|
|
16
|
+
__version_tuple__ = version_tuple = (0, 13, 1)
|
|
Binary file
|
numcodecs/zfpy.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
from contextlib import suppress
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
_zfpy = None
|
|
6
|
+
|
|
7
|
+
_zfpy_version: tuple = ()
|
|
8
|
+
with suppress(PackageNotFoundError):
|
|
9
|
+
_zfpy_version = tuple(map(int, version("zfpy").split(".")))
|
|
10
|
+
|
|
11
|
+
if _zfpy_version:
|
|
12
|
+
# Check NumPy version
|
|
13
|
+
_numpy_version: tuple = tuple(map(int, version("numpy").split('.')))
|
|
14
|
+
if _numpy_version >= (2, 0, 0) and _zfpy_version <= (1, 0, 1): # pragma: no cover
|
|
15
|
+
_zfpy_version = ()
|
|
16
|
+
warnings.warn(
|
|
17
|
+
"NumPy version >= 2.0.0 detected. The zfpy library is incompatible with this version of NumPy. "
|
|
18
|
+
"Please downgrade to NumPy < 2.0.0 or wait for an update from zfpy.",
|
|
19
|
+
UserWarning,
|
|
20
|
+
stacklevel=2,
|
|
21
|
+
)
|
|
22
|
+
else:
|
|
23
|
+
with suppress(ImportError):
|
|
24
|
+
import zfpy as _zfpy
|
|
25
|
+
|
|
26
|
+
if _zfpy:
|
|
27
|
+
import numpy as np
|
|
28
|
+
|
|
29
|
+
from .abc import Codec
|
|
30
|
+
from .compat import ensure_bytes, ensure_contiguous_ndarray, ndarray_copy
|
|
31
|
+
|
|
32
|
+
# noinspection PyShadowingBuiltins
|
|
33
|
+
class ZFPY(Codec):
|
|
34
|
+
"""Codec providing compression using zfpy via the Python standard
|
|
35
|
+
library.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
mode : integer
|
|
40
|
+
One of the zfpy mode choice, e.g., ``zfpy.mode_fixed_accuracy``.
|
|
41
|
+
tolerance : double, optional
|
|
42
|
+
A double-precision number, specifying the compression accuracy needed.
|
|
43
|
+
rate : double, optional
|
|
44
|
+
A double-precision number, specifying the compression rate needed.
|
|
45
|
+
precision : int, optional
|
|
46
|
+
A integer number, specifying the compression precision needed.
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
codec_id = "zfpy"
|
|
51
|
+
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
mode=_zfpy.mode_fixed_accuracy,
|
|
55
|
+
tolerance=-1,
|
|
56
|
+
rate=-1,
|
|
57
|
+
precision=-1,
|
|
58
|
+
compression_kwargs=None,
|
|
59
|
+
):
|
|
60
|
+
self.mode = mode
|
|
61
|
+
if mode == _zfpy.mode_fixed_accuracy:
|
|
62
|
+
self.compression_kwargs = {"tolerance": tolerance}
|
|
63
|
+
elif mode == _zfpy.mode_fixed_rate:
|
|
64
|
+
self.compression_kwargs = {"rate": rate}
|
|
65
|
+
elif mode == _zfpy.mode_fixed_precision:
|
|
66
|
+
self.compression_kwargs = {"precision": precision}
|
|
67
|
+
|
|
68
|
+
self.tolerance = tolerance
|
|
69
|
+
self.rate = rate
|
|
70
|
+
self.precision = precision
|
|
71
|
+
|
|
72
|
+
def encode(self, buf):
|
|
73
|
+
# not flatten c-order array and raise exception for f-order array
|
|
74
|
+
if not isinstance(buf, np.ndarray):
|
|
75
|
+
raise TypeError(
|
|
76
|
+
"The zfp codec does not support none numpy arrays."
|
|
77
|
+
f" Your buffers were {type(buf)}."
|
|
78
|
+
)
|
|
79
|
+
if buf.flags.c_contiguous:
|
|
80
|
+
flatten = False
|
|
81
|
+
else:
|
|
82
|
+
raise ValueError(
|
|
83
|
+
"The zfp codec does not support F order arrays. "
|
|
84
|
+
f"Your arrays flags were {buf.flags}."
|
|
85
|
+
)
|
|
86
|
+
buf = ensure_contiguous_ndarray(buf, flatten=flatten)
|
|
87
|
+
|
|
88
|
+
# do compression
|
|
89
|
+
return _zfpy.compress_numpy(buf, write_header=True, **self.compression_kwargs)
|
|
90
|
+
|
|
91
|
+
def decode(self, buf, out=None):
|
|
92
|
+
# normalise inputs
|
|
93
|
+
buf = ensure_bytes(buf)
|
|
94
|
+
if out is not None:
|
|
95
|
+
out = ensure_contiguous_ndarray(out)
|
|
96
|
+
|
|
97
|
+
# do decompression
|
|
98
|
+
dec = _zfpy.decompress_numpy(buf)
|
|
99
|
+
|
|
100
|
+
# handle destination
|
|
101
|
+
if out is not None:
|
|
102
|
+
return ndarray_copy(dec, out)
|
|
103
|
+
else:
|
|
104
|
+
return dec
|
|
105
|
+
|
|
106
|
+
def __repr__(self):
|
|
107
|
+
return (
|
|
108
|
+
f"{type(self).__name__}(mode={self.mode!r}, "
|
|
109
|
+
f"tolerance={self.tolerance}, rate={self.rate}, "
|
|
110
|
+
f"precision={self.precision})"
|
|
111
|
+
)
|