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.
- numcodecs/__init__.py +146 -0
- numcodecs/_shuffle.cpython-311-darwin.so +0 -0
- numcodecs/abc.py +127 -0
- numcodecs/astype.py +72 -0
- numcodecs/base64.py +26 -0
- numcodecs/bitround.py +80 -0
- numcodecs/blosc.cpython-311-darwin.so +0 -0
- numcodecs/bz2.py +45 -0
- numcodecs/categorize.py +98 -0
- numcodecs/checksum32.py +183 -0
- numcodecs/compat.py +206 -0
- numcodecs/compat_ext.cpython-311-darwin.so +0 -0
- numcodecs/delta.py +94 -0
- numcodecs/errors.py +26 -0
- numcodecs/fixedscaleoffset.py +130 -0
- numcodecs/fletcher32.cpython-311-darwin.so +0 -0
- numcodecs/gzip.py +50 -0
- numcodecs/jenkins.cpython-311-darwin.so +0 -0
- numcodecs/json.py +107 -0
- numcodecs/lz4.cpython-311-darwin.so +0 -0
- numcodecs/lzma.py +72 -0
- numcodecs/msgpacks.py +86 -0
- numcodecs/ndarray_like.py +65 -0
- numcodecs/packbits.py +82 -0
- numcodecs/pcodec.py +118 -0
- numcodecs/pickles.py +55 -0
- numcodecs/quantize.py +98 -0
- numcodecs/registry.py +74 -0
- numcodecs/shuffle.py +61 -0
- numcodecs/tests/__init__.py +3 -0
- numcodecs/tests/common.py +285 -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 +284 -0
- numcodecs/tests/test_bz2.py +66 -0
- numcodecs/tests/test_categorize.py +87 -0
- numcodecs/tests/test_checksum32.py +154 -0
- numcodecs/tests/test_compat.py +111 -0
- numcodecs/tests/test_delta.py +61 -0
- numcodecs/tests/test_entrypoints.py +24 -0
- numcodecs/tests/test_entrypoints_backport.py +36 -0
- numcodecs/tests/test_fixedscaleoffset.py +77 -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 +94 -0
- numcodecs/tests/test_msgpacks.py +126 -0
- numcodecs/tests/test_ndarray_like.py +48 -0
- numcodecs/tests/test_packbits.py +39 -0
- numcodecs/tests/test_pcodec.py +90 -0
- numcodecs/tests/test_pickles.py +61 -0
- numcodecs/tests/test_quantize.py +76 -0
- numcodecs/tests/test_registry.py +43 -0
- numcodecs/tests/test_shuffle.py +166 -0
- numcodecs/tests/test_vlen_array.py +97 -0
- numcodecs/tests/test_vlen_bytes.py +97 -0
- numcodecs/tests/test_vlen_utf8.py +91 -0
- numcodecs/tests/test_zarr3.py +279 -0
- numcodecs/tests/test_zarr3_import.py +13 -0
- numcodecs/tests/test_zfpy.py +104 -0
- numcodecs/tests/test_zlib.py +94 -0
- numcodecs/tests/test_zstd.py +92 -0
- numcodecs/version.py +21 -0
- numcodecs/vlen.cpython-311-darwin.so +0 -0
- numcodecs/zarr3.py +401 -0
- numcodecs/zfpy.py +113 -0
- numcodecs/zlib.py +42 -0
- numcodecs/zstd.cpython-311-darwin.so +0 -0
- numcodecs-0.16.0.dist-info/METADATA +66 -0
- numcodecs-0.16.0.dist-info/RECORD +79 -0
- numcodecs-0.16.0.dist-info/WHEEL +6 -0
- numcodecs-0.16.0.dist-info/entry_points.txt +22 -0
- numcodecs-0.16.0.dist-info/licenses/LICENSE.txt +21 -0
- numcodecs-0.16.0.dist-info/top_level.txt +1 -0
|
@@ -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_to_bytes,
|
|
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_to_bytes(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_to_bytes(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_to_bytes(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)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pytest
|
|
5
|
+
from numpy.testing import assert_array_almost_equal, assert_array_equal
|
|
6
|
+
|
|
7
|
+
from numcodecs.quantize import Quantize
|
|
8
|
+
from numcodecs.tests.common import (
|
|
9
|
+
check_backwards_compatibility,
|
|
10
|
+
check_config,
|
|
11
|
+
check_encode_decode,
|
|
12
|
+
check_repr,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
arrays = [
|
|
16
|
+
np.linspace(100, 200, 1000, dtype='<f8'),
|
|
17
|
+
np.random.normal(loc=0, scale=1, size=1000).astype('<f8'),
|
|
18
|
+
np.linspace(100, 200, 1000, dtype='<f8').reshape(100, 10),
|
|
19
|
+
np.linspace(100, 200, 1000, dtype='<f8').reshape(100, 10, order='F'),
|
|
20
|
+
np.linspace(100, 200, 1000, dtype='<f8').reshape(10, 10, 10),
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
codecs = [
|
|
25
|
+
Quantize(digits=-1, dtype='<f8', astype='<f2'),
|
|
26
|
+
Quantize(digits=0, dtype='<f8', astype='<f2'),
|
|
27
|
+
Quantize(digits=1, dtype='<f8', astype='<f2'),
|
|
28
|
+
Quantize(digits=5, dtype='<f8', astype='<f4'),
|
|
29
|
+
Quantize(digits=12, dtype='<f8', astype='<f8'),
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_encode_decode():
|
|
34
|
+
for arr, codec in itertools.product(arrays, codecs):
|
|
35
|
+
check_encode_decode(arr, codec, precision=codec.digits)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_encode():
|
|
39
|
+
for arr, codec in itertools.product(arrays, codecs):
|
|
40
|
+
if arr.flags.f_contiguous:
|
|
41
|
+
order = 'F'
|
|
42
|
+
else:
|
|
43
|
+
order = 'C'
|
|
44
|
+
enc = codec.encode(arr).reshape(arr.shape, order=order)
|
|
45
|
+
assert_array_almost_equal(arr, enc, decimal=codec.digits)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_decode():
|
|
49
|
+
# decode is a no-op
|
|
50
|
+
for arr, codec in itertools.product(arrays, codecs):
|
|
51
|
+
enc = codec.encode(arr)
|
|
52
|
+
dec = codec.decode(enc)
|
|
53
|
+
assert_array_equal(enc, dec)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_config():
|
|
57
|
+
for codec in codecs:
|
|
58
|
+
check_config(codec)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_repr():
|
|
62
|
+
check_repr("Quantize(digits=2, dtype='<f8', astype='<f2')")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_errors():
|
|
66
|
+
with pytest.raises(ValueError):
|
|
67
|
+
Quantize(digits=2, dtype='i4')
|
|
68
|
+
with pytest.raises(ValueError):
|
|
69
|
+
Quantize(digits=2, dtype=object)
|
|
70
|
+
with pytest.raises(ValueError):
|
|
71
|
+
Quantize(digits=2, dtype='f8', astype=object)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_backwards_compatibility():
|
|
75
|
+
precision = [codec.digits for codec in codecs]
|
|
76
|
+
check_backwards_compatibility(Quantize.codec_id, arrays, codecs, precision=precision)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
import numcodecs
|
|
6
|
+
from numcodecs.errors import UnknownCodecError
|
|
7
|
+
from numcodecs.registry import get_codec
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_registry_errors():
|
|
11
|
+
with pytest.raises(UnknownCodecError, match='foo'):
|
|
12
|
+
get_codec({'id': 'foo'})
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_get_codec_argument():
|
|
16
|
+
# Check that get_codec doesn't modify its argument.
|
|
17
|
+
arg = {"id": "json2"}
|
|
18
|
+
before = dict(arg)
|
|
19
|
+
get_codec(arg)
|
|
20
|
+
assert before == arg
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_all_classes_registered():
|
|
24
|
+
"""
|
|
25
|
+
find all Codec subclasses in this repository and check that they
|
|
26
|
+
have been registered.
|
|
27
|
+
|
|
28
|
+
see #346 for more info
|
|
29
|
+
"""
|
|
30
|
+
missing = {
|
|
31
|
+
obj.codec_id
|
|
32
|
+
for _, submod in inspect.getmembers(numcodecs, inspect.ismodule)
|
|
33
|
+
for _, obj in inspect.getmembers(submod)
|
|
34
|
+
if (
|
|
35
|
+
inspect.isclass(obj)
|
|
36
|
+
and issubclass(obj, numcodecs.abc.Codec)
|
|
37
|
+
and obj.codec_id not in numcodecs.registry.codec_registry
|
|
38
|
+
and obj.codec_id is not None # remove `None`
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if missing:
|
|
43
|
+
raise Exception(f"these codecs are missing: {missing}") # pragma: no cover
|