numcodecs 0.12.0__cp311-cp311-macosx_11_0_arm64.whl → 0.13.0__cp311-cp311-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.
Potentially problematic release.
This version of numcodecs might be problematic. Click here for more details.
- numcodecs/__init__.py +29 -1
- numcodecs/_shuffle.cpython-311-darwin.so +0 -0
- numcodecs/abc.py +7 -7
- numcodecs/astype.py +2 -8
- numcodecs/blosc.cpython-311-darwin.so +0 -0
- numcodecs/bz2.py +0 -2
- numcodecs/categorize.py +14 -13
- numcodecs/checksum32.py +2 -5
- numcodecs/compat.py +2 -6
- numcodecs/compat_ext.cpython-311-darwin.so +0 -0
- numcodecs/delta.py +2 -8
- numcodecs/fixedscaleoffset.py +8 -6
- numcodecs/fletcher32.cpython-311-darwin.so +0 -0
- numcodecs/gzip.py +1 -5
- numcodecs/jenkins.cpython-311-darwin.so +0 -0
- numcodecs/json.py +28 -10
- numcodecs/lz4.cpython-311-darwin.so +0 -0
- numcodecs/lzma.py +14 -8
- numcodecs/msgpacks.py +13 -9
- numcodecs/ndarray_like.py +7 -12
- numcodecs/packbits.py +1 -3
- numcodecs/pcodec.py +89 -0
- numcodecs/pickles.py +1 -2
- numcodecs/quantize.py +9 -7
- numcodecs/registry.py +2 -6
- numcodecs/shuffle.py +2 -4
- numcodecs/tests/common.py +36 -22
- numcodecs/tests/package_with_entrypoint/__init__.py +0 -1
- numcodecs/tests/test_astype.py +7 -5
- numcodecs/tests/test_base64.py +8 -8
- numcodecs/tests/test_blosc.py +22 -19
- numcodecs/tests/test_bz2.py +12 -8
- numcodecs/tests/test_categorize.py +9 -11
- numcodecs/tests/test_checksum32.py +8 -4
- numcodecs/tests/test_compat.py +7 -10
- numcodecs/tests/test_delta.py +6 -2
- numcodecs/tests/test_entrypoints.py +2 -1
- numcodecs/tests/test_entrypoints_backport.py +36 -0
- numcodecs/tests/test_fixedscaleoffset.py +6 -2
- numcodecs/tests/test_fletcher32.py +13 -6
- numcodecs/tests/test_gzip.py +12 -8
- numcodecs/tests/test_jenkins.py +41 -42
- numcodecs/tests/test_json.py +17 -7
- numcodecs/tests/test_lz4.py +14 -12
- numcodecs/tests/test_lzma.py +13 -9
- numcodecs/tests/test_msgpacks.py +8 -3
- numcodecs/tests/test_packbits.py +6 -2
- numcodecs/tests/test_pcodec.py +81 -0
- numcodecs/tests/test_pickles.py +11 -7
- numcodecs/tests/test_quantize.py +6 -2
- numcodecs/tests/test_shuffle.py +34 -23
- numcodecs/tests/test_vlen_array.py +12 -13
- numcodecs/tests/test_vlen_bytes.py +11 -5
- numcodecs/tests/test_vlen_utf8.py +12 -4
- numcodecs/tests/test_zfpy.py +3 -9
- numcodecs/tests/test_zlib.py +12 -8
- numcodecs/tests/test_zstd.py +32 -13
- numcodecs/version.py +2 -2
- numcodecs/vlen.cpython-311-darwin.so +0 -0
- numcodecs/zfpy.py +28 -12
- numcodecs/zlib.py +0 -2
- numcodecs/zstd.cpython-311-darwin.so +0 -0
- {numcodecs-0.12.0.dist-info → numcodecs-0.13.0.dist-info}/METADATA +8 -3
- numcodecs-0.13.0.dist-info/RECORD +74 -0
- {numcodecs-0.12.0.dist-info → numcodecs-0.13.0.dist-info}/WHEEL +1 -1
- numcodecs-0.12.0.dist-info/RECORD +0 -71
- {numcodecs-0.12.0.dist-info → numcodecs-0.13.0.dist-info}/LICENSE.txt +0 -0
- {numcodecs-0.12.0.dist-info → numcodecs-0.13.0.dist-info}/top_level.txt +0 -0
numcodecs/pcodec.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from typing import Optional, Literal
|
|
2
|
+
|
|
3
|
+
import numcodecs
|
|
4
|
+
import numcodecs.abc
|
|
5
|
+
from numcodecs.compat import ensure_contiguous_ndarray
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
from pcodec import standalone, ChunkConfig, PagingSpec, ModeSpec
|
|
9
|
+
except ImportError: # pragma: no cover
|
|
10
|
+
standalone = None
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
DEFAULT_MAX_PAGE_N = 262144
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PCodec(numcodecs.abc.Codec):
|
|
17
|
+
"""
|
|
18
|
+
PCodec (or pco, pronounced "pico") losslessly compresses and decompresses
|
|
19
|
+
numerical sequences with high compression ratio and fast speed.
|
|
20
|
+
|
|
21
|
+
See `PCodec Repo <https://github.com/mwlon/pcodec>`_ for more information.
|
|
22
|
+
|
|
23
|
+
PCodec supports only the following numerical dtypes: uint16, uint32, uint64,
|
|
24
|
+
int16, int32, int64, float16, float32, and float64.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
level : int
|
|
29
|
+
A compression level from 0-12, where 12 take the longest and compresses
|
|
30
|
+
the most.
|
|
31
|
+
delta_encoding_order : init or None
|
|
32
|
+
Either a delta encoding level from 0-7 or None. If set to None, pcodec
|
|
33
|
+
will try to infer the optimal delta encoding order.
|
|
34
|
+
mode_spec : {'auto', 'classic'}
|
|
35
|
+
Configures whether Pcodec should try to infer the best "mode" or
|
|
36
|
+
structure of the data (e.g. approximate multiples of 0.1) to improve
|
|
37
|
+
compression ratio, or skip this step and just use the numbers as-is
|
|
38
|
+
(Classic mode).
|
|
39
|
+
equal_pages_up_to : int
|
|
40
|
+
Divide the chunk into equal pages of up to this many numbers.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
codec_id = "pcodec"
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
level: int = 8,
|
|
48
|
+
delta_encoding_order: Optional[int] = None,
|
|
49
|
+
equal_pages_up_to: int = 262144,
|
|
50
|
+
# TODO one day, add support for the Try* mode specs
|
|
51
|
+
mode_spec: Literal['auto', 'classic'] = 'auto',
|
|
52
|
+
):
|
|
53
|
+
if standalone is None: # pragma: no cover
|
|
54
|
+
raise ImportError("pcodec must be installed to use the PCodec codec.")
|
|
55
|
+
|
|
56
|
+
# note that we use `level` instead of `compression_level` to
|
|
57
|
+
# match other codecs
|
|
58
|
+
self.level = level
|
|
59
|
+
self.delta_encoding_order = delta_encoding_order
|
|
60
|
+
self.equal_pages_up_to = equal_pages_up_to
|
|
61
|
+
self.mode_spec = mode_spec
|
|
62
|
+
|
|
63
|
+
def encode(self, buf):
|
|
64
|
+
buf = ensure_contiguous_ndarray(buf)
|
|
65
|
+
|
|
66
|
+
match self.mode_spec:
|
|
67
|
+
case 'auto':
|
|
68
|
+
mode_spec = ModeSpec.auto()
|
|
69
|
+
case 'classic':
|
|
70
|
+
mode_spec = ModeSpec.classic()
|
|
71
|
+
case _:
|
|
72
|
+
raise ValueError(f"unknown value for mode_spec: {self.mode_spec}")
|
|
73
|
+
paging_spec = PagingSpec.equal_pages_up_to(self.equal_pages_up_to)
|
|
74
|
+
|
|
75
|
+
config = ChunkConfig(
|
|
76
|
+
compression_level=self.level,
|
|
77
|
+
delta_encoding_order=self.delta_encoding_order,
|
|
78
|
+
mode_spec=mode_spec,
|
|
79
|
+
paging_spec=paging_spec,
|
|
80
|
+
)
|
|
81
|
+
return standalone.simple_compress(buf, config)
|
|
82
|
+
|
|
83
|
+
def decode(self, buf, out=None):
|
|
84
|
+
if out is not None:
|
|
85
|
+
out = ensure_contiguous_ndarray(out)
|
|
86
|
+
standalone.simple_decompress_into(buf, out)
|
|
87
|
+
return out
|
|
88
|
+
else:
|
|
89
|
+
return standalone.simple_decompress(buf)
|
numcodecs/pickles.py
CHANGED
numcodecs/quantize.py
CHANGED
|
@@ -60,19 +60,18 @@ class Quantize(Codec):
|
|
|
60
60
|
raise ValueError('only floating point data types are supported')
|
|
61
61
|
|
|
62
62
|
def encode(self, buf):
|
|
63
|
-
|
|
64
63
|
# normalise input
|
|
65
64
|
arr = ensure_ndarray(buf).view(self.dtype)
|
|
66
65
|
|
|
67
66
|
# apply scaling
|
|
68
|
-
precision = 10.
|
|
67
|
+
precision = 10.0**-self.digits
|
|
69
68
|
exp = math.log(precision, 10)
|
|
70
69
|
if exp < 0:
|
|
71
70
|
exp = int(math.floor(exp))
|
|
72
71
|
else:
|
|
73
72
|
exp = int(math.ceil(exp))
|
|
74
|
-
bits = math.ceil(math.log(10.
|
|
75
|
-
scale = 2.
|
|
73
|
+
bits = math.ceil(math.log(10.0**-exp, 2))
|
|
74
|
+
scale = 2.0**bits
|
|
76
75
|
enc = np.around(scale * arr) / scale
|
|
77
76
|
|
|
78
77
|
# cast dtype
|
|
@@ -92,12 +91,15 @@ class Quantize(Codec):
|
|
|
92
91
|
id=self.codec_id,
|
|
93
92
|
digits=self.digits,
|
|
94
93
|
dtype=self.dtype.str,
|
|
95
|
-
astype=self.astype.str
|
|
94
|
+
astype=self.astype.str,
|
|
96
95
|
)
|
|
97
96
|
|
|
98
97
|
def __repr__(self):
|
|
99
|
-
r = '%s(digits=%s, dtype=%r' %
|
|
100
|
-
|
|
98
|
+
r = '%s(digits=%s, dtype=%r' % (
|
|
99
|
+
type(self).__name__,
|
|
100
|
+
self.digits,
|
|
101
|
+
self.dtype.str,
|
|
102
|
+
)
|
|
101
103
|
if self.astype != self.dtype:
|
|
102
104
|
r += ', astype=%r' % self.astype.str
|
|
103
105
|
r += ')'
|
numcodecs/registry.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""The registry module provides some simple convenience functions to enable
|
|
2
2
|
applications to dynamically register and look-up codec classes."""
|
|
3
|
+
|
|
3
4
|
from importlib.metadata import entry_points
|
|
4
5
|
import logging
|
|
5
6
|
|
|
@@ -11,12 +12,7 @@ entries = {}
|
|
|
11
12
|
def run_entrypoints():
|
|
12
13
|
entries.clear()
|
|
13
14
|
eps = entry_points()
|
|
14
|
-
|
|
15
|
-
# If entry_points() has a select method, use that. Python 3.10+
|
|
16
|
-
entries.update({e.name: e for e in eps.select(group="numcodecs.codecs")})
|
|
17
|
-
else:
|
|
18
|
-
# Otherwise, fallback to using get
|
|
19
|
-
entries.update(eps.get("numcodecs.codecs", []))
|
|
15
|
+
entries.update({e.name: e for e in eps.select(group="numcodecs.codecs")})
|
|
20
16
|
|
|
21
17
|
|
|
22
18
|
run_entrypoints()
|
numcodecs/shuffle.py
CHANGED
|
@@ -28,7 +28,7 @@ class Shuffle(Codec):
|
|
|
28
28
|
out = ensure_contiguous_ndarray(out)
|
|
29
29
|
|
|
30
30
|
if self.elementsize <= 1:
|
|
31
|
-
out.view(buf.dtype)[:len(buf)] = buf[:] # no shuffling needed
|
|
31
|
+
out.view(buf.dtype)[: len(buf)] = buf[:] # no shuffling needed
|
|
32
32
|
return buf, out
|
|
33
33
|
|
|
34
34
|
if buf.nbytes % self.elementsize != 0:
|
|
@@ -57,7 +57,5 @@ class Shuffle(Codec):
|
|
|
57
57
|
return out
|
|
58
58
|
|
|
59
59
|
def __repr__(self):
|
|
60
|
-
r = '%s(elementsize=%s)' %
|
|
61
|
-
(type(self).__name__,
|
|
62
|
-
self.elementsize)
|
|
60
|
+
r = '%s(elementsize=%s)' % (type(self).__name__, self.elementsize)
|
|
63
61
|
return r
|
numcodecs/tests/common.py
CHANGED
|
@@ -11,18 +11,28 @@ import pytest
|
|
|
11
11
|
|
|
12
12
|
from numcodecs.compat import ensure_bytes, ensure_ndarray
|
|
13
13
|
from numcodecs.registry import get_codec
|
|
14
|
+
|
|
14
15
|
# star import needed for repr tests so eval finds names
|
|
15
16
|
from numcodecs import * # noqa
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
greetings = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
greetings = [
|
|
20
|
+
'¡Hola mundo!',
|
|
21
|
+
'Hej Världen!',
|
|
22
|
+
'Servus Woid!',
|
|
23
|
+
'Hei maailma!',
|
|
24
|
+
'Xin chào thế giới',
|
|
25
|
+
'Njatjeta Botë!',
|
|
26
|
+
'Γεια σου κόσμε!',
|
|
27
|
+
'こんにちは世界',
|
|
28
|
+
'世界,你好!',
|
|
29
|
+
'Helló, világ!',
|
|
30
|
+
'Zdravo svete!',
|
|
31
|
+
'เฮลโลเวิลด์',
|
|
32
|
+
]
|
|
22
33
|
|
|
23
34
|
|
|
24
35
|
def compare_arrays(arr, res, precision=None):
|
|
25
|
-
|
|
26
36
|
# ensure numpy array with matching dtype
|
|
27
37
|
res = ensure_ndarray(res).view(arr.dtype)
|
|
28
38
|
|
|
@@ -43,7 +53,6 @@ def compare_arrays(arr, res, precision=None):
|
|
|
43
53
|
|
|
44
54
|
|
|
45
55
|
def check_encode_decode(arr, codec, precision=None):
|
|
46
|
-
|
|
47
56
|
# N.B., watch out here with blosc compressor, if the itemsize of
|
|
48
57
|
# the source buffer is different then the results of encoding
|
|
49
58
|
# (i.e., compression) may be different. Hence we *do not* require that
|
|
@@ -112,7 +121,6 @@ def check_encode_decode(arr, codec, precision=None):
|
|
|
112
121
|
|
|
113
122
|
|
|
114
123
|
def check_encode_decode_partial(arr, codec, precision=None):
|
|
115
|
-
|
|
116
124
|
# N.B., watch out here with blosc compressor, if the itemsize of
|
|
117
125
|
# the source buffer is different then the results of encoding
|
|
118
126
|
# (i.e., compression) may be different. Hence we *do not* require that
|
|
@@ -122,7 +130,7 @@ def check_encode_decode_partial(arr, codec, precision=None):
|
|
|
122
130
|
|
|
123
131
|
itemsize = arr.itemsize
|
|
124
132
|
start, nitems = 5, 10
|
|
125
|
-
compare_arr = arr[start:start+nitems]
|
|
133
|
+
compare_arr = arr[start : start + nitems]
|
|
126
134
|
# test encoding of numpy array
|
|
127
135
|
enc = codec.encode(arr)
|
|
128
136
|
dec = codec.decode_partial(enc, start, nitems)
|
|
@@ -135,19 +143,19 @@ def check_encode_decode_partial(arr, codec, precision=None):
|
|
|
135
143
|
# test partial decode of encoded bytes
|
|
136
144
|
buf = arr.tobytes(order='A')
|
|
137
145
|
enc = codec.encode(buf)
|
|
138
|
-
dec = codec.decode_partial(enc, start*itemsize, nitems*itemsize, out=out)
|
|
146
|
+
dec = codec.decode_partial(enc, start * itemsize, nitems * itemsize, out=out)
|
|
139
147
|
compare_arrays(compare_arr, dec, precision=precision)
|
|
140
148
|
|
|
141
149
|
# test partial decode of encoded bytearray
|
|
142
150
|
buf = bytearray(arr.tobytes(order='A'))
|
|
143
151
|
enc = codec.encode(buf)
|
|
144
|
-
dec = codec.decode_partial(enc, start*itemsize, nitems*itemsize, out=out)
|
|
152
|
+
dec = codec.decode_partial(enc, start * itemsize, nitems * itemsize, out=out)
|
|
145
153
|
compare_arrays(compare_arr, dec, precision=precision)
|
|
146
154
|
|
|
147
155
|
# test partial decode of encoded array.array
|
|
148
156
|
buf = array.array('b', arr.tobytes(order='A'))
|
|
149
157
|
enc = codec.encode(buf)
|
|
150
|
-
dec = codec.decode_partial(enc, start*itemsize, nitems*itemsize, out=out)
|
|
158
|
+
dec = codec.decode_partial(enc, start * itemsize, nitems * itemsize, out=out)
|
|
151
159
|
compare_arrays(compare_arr, dec, precision=precision)
|
|
152
160
|
|
|
153
161
|
# # decoding should support any object exporting the buffer protocol,
|
|
@@ -156,32 +164,31 @@ def check_encode_decode_partial(arr, codec, precision=None):
|
|
|
156
164
|
enc_bytes = ensure_bytes(enc)
|
|
157
165
|
|
|
158
166
|
# test decoding of raw bytes into numpy array
|
|
159
|
-
dec = codec.decode_partial(enc_bytes, start*itemsize, nitems*itemsize, out=out)
|
|
167
|
+
dec = codec.decode_partial(enc_bytes, start * itemsize, nitems * itemsize, out=out)
|
|
160
168
|
compare_arrays(compare_arr, dec, precision=precision)
|
|
161
169
|
|
|
162
170
|
# test partial decoding of bytearray
|
|
163
|
-
dec = codec.decode_partial(bytearray(enc_bytes), start*itemsize, nitems*itemsize, out=out)
|
|
171
|
+
dec = codec.decode_partial(bytearray(enc_bytes), start * itemsize, nitems * itemsize, out=out)
|
|
164
172
|
compare_arrays(compare_arr, dec, precision=precision)
|
|
165
173
|
|
|
166
174
|
# test partial decoding of array.array
|
|
167
175
|
buf = array.array('b', enc_bytes)
|
|
168
|
-
dec = codec.decode_partial(buf, start*itemsize, nitems*itemsize, out=out)
|
|
176
|
+
dec = codec.decode_partial(buf, start * itemsize, nitems * itemsize, out=out)
|
|
169
177
|
compare_arrays(compare_arr, dec, precision=precision)
|
|
170
178
|
|
|
171
179
|
# test decoding of numpy array into numpy array
|
|
172
180
|
buf = np.frombuffer(enc_bytes, dtype='u1')
|
|
173
|
-
dec = codec.decode_partial(buf, start*itemsize, nitems*itemsize, out=out)
|
|
181
|
+
dec = codec.decode_partial(buf, start * itemsize, nitems * itemsize, out=out)
|
|
174
182
|
compare_arrays(compare_arr, dec, precision=precision)
|
|
175
183
|
|
|
176
184
|
# test decoding directly into bytearray
|
|
177
185
|
out = bytearray(compare_arr.nbytes)
|
|
178
|
-
codec.decode_partial(enc_bytes, start*itemsize, nitems*itemsize, out=out)
|
|
186
|
+
codec.decode_partial(enc_bytes, start * itemsize, nitems * itemsize, out=out)
|
|
179
187
|
# noinspection PyTypeChecker
|
|
180
188
|
compare_arrays(compare_arr, out, precision=precision)
|
|
181
189
|
|
|
182
190
|
|
|
183
191
|
def assert_array_items_equal(res, arr):
|
|
184
|
-
|
|
185
192
|
assert isinstance(res, np.ndarray)
|
|
186
193
|
res = res.reshape(-1, order='A')
|
|
187
194
|
arr = arr.reshape(-1, order='A')
|
|
@@ -203,7 +210,6 @@ def assert_array_items_equal(res, arr):
|
|
|
203
210
|
|
|
204
211
|
|
|
205
212
|
def check_encode_decode_array(arr, codec):
|
|
206
|
-
|
|
207
213
|
enc = codec.encode(arr)
|
|
208
214
|
dec = codec.decode(enc)
|
|
209
215
|
assert_array_items_equal(arr, dec)
|
|
@@ -217,6 +223,16 @@ def check_encode_decode_array(arr, codec):
|
|
|
217
223
|
assert_array_items_equal(arr, dec)
|
|
218
224
|
|
|
219
225
|
|
|
226
|
+
def check_encode_decode_array_to_bytes(arr, codec):
|
|
227
|
+
enc = codec.encode(arr)
|
|
228
|
+
dec = codec.decode(enc)
|
|
229
|
+
assert_array_items_equal(arr, dec)
|
|
230
|
+
|
|
231
|
+
out = np.empty_like(arr)
|
|
232
|
+
codec.decode(enc, out=out)
|
|
233
|
+
assert_array_items_equal(arr, out)
|
|
234
|
+
|
|
235
|
+
|
|
220
236
|
def check_config(codec):
|
|
221
237
|
config = codec.get_config()
|
|
222
238
|
# round-trip through JSON to check serialization
|
|
@@ -232,7 +248,6 @@ def check_repr(stmt):
|
|
|
232
248
|
|
|
233
249
|
|
|
234
250
|
def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, prefix=None):
|
|
235
|
-
|
|
236
251
|
# setup directory to hold data fixture
|
|
237
252
|
if prefix:
|
|
238
253
|
fixture_dir = os.path.join('fixture', codec_id, prefix)
|
|
@@ -249,7 +264,6 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
|
|
|
249
264
|
|
|
250
265
|
# load fixture data
|
|
251
266
|
for arr_fn in glob(os.path.join(fixture_dir, 'array.*.npy')):
|
|
252
|
-
|
|
253
267
|
# setup
|
|
254
268
|
i = int(arr_fn.split('.')[-2])
|
|
255
269
|
arr = np.load(arr_fn, allow_pickle=True)
|
|
@@ -260,7 +274,6 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
|
|
|
260
274
|
order = 'C'
|
|
261
275
|
|
|
262
276
|
for j, codec in enumerate(codecs):
|
|
263
|
-
|
|
264
277
|
if codec is None:
|
|
265
278
|
pytest.skip("codec has been removed")
|
|
266
279
|
|
|
@@ -334,7 +347,8 @@ def check_max_buffer_size(codec):
|
|
|
334
347
|
np.zeros(max_buffer_size + 1, dtype=np.int8),
|
|
335
348
|
np.zeros(max_buffer_size + 2, dtype=np.int8),
|
|
336
349
|
np.zeros(max_buffer_size, dtype=np.int16),
|
|
337
|
-
np.zeros(max_buffer_size, dtype=np.int32)
|
|
350
|
+
np.zeros(max_buffer_size, dtype=np.int32),
|
|
351
|
+
]
|
|
338
352
|
for buf in buffers:
|
|
339
353
|
with pytest.raises(ValueError):
|
|
340
354
|
codec.encode(buf)
|
numcodecs/tests/test_astype.py
CHANGED
|
@@ -3,8 +3,12 @@ from numpy.testing import assert_array_equal
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
from numcodecs.astype import AsType
|
|
6
|
-
from numcodecs.tests.common import
|
|
7
|
-
|
|
6
|
+
from numcodecs.tests.common import (
|
|
7
|
+
check_encode_decode,
|
|
8
|
+
check_config,
|
|
9
|
+
check_repr,
|
|
10
|
+
check_backwards_compatibility,
|
|
11
|
+
)
|
|
8
12
|
|
|
9
13
|
|
|
10
14
|
# mix of dtypes: integer, float
|
|
@@ -55,7 +59,6 @@ def test_repr():
|
|
|
55
59
|
|
|
56
60
|
|
|
57
61
|
def test_backwards_compatibility():
|
|
58
|
-
|
|
59
62
|
# integers
|
|
60
63
|
arrs = [
|
|
61
64
|
np.arange(1000, dtype='<i4'),
|
|
@@ -70,5 +73,4 @@ def test_backwards_compatibility():
|
|
|
70
73
|
np.random.normal(loc=1000, scale=1, size=(10, 10, 10)).astype('<f8'),
|
|
71
74
|
]
|
|
72
75
|
codec = AsType(encode_dtype='<f4', decode_dtype='<f8')
|
|
73
|
-
check_backwards_compatibility(AsType.codec_id, arrs, [codec], precision=[3],
|
|
74
|
-
prefix='f')
|
|
76
|
+
check_backwards_compatibility(AsType.codec_id, arrs, [codec], precision=[3], prefix='f')
|
numcodecs/tests/test_base64.py
CHANGED
|
@@ -29,14 +29,14 @@ arrays = [
|
|
|
29
29
|
np.random.normal(loc=1000, scale=1, size=(100, 10)),
|
|
30
30
|
np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order="F"),
|
|
31
31
|
np.random.choice([b"a", b"bb", b"ccc"], size=1000).reshape(10, 10, 10),
|
|
32
|
-
np.random.randint(0, 2
|
|
33
|
-
np.random.randint(0, 2
|
|
34
|
-
np.random.randint(0, 2
|
|
35
|
-
np.random.randint(0, 2
|
|
36
|
-
np.random.randint(-(2
|
|
37
|
-
np.random.randint(-(2
|
|
38
|
-
np.random.randint(-(2
|
|
39
|
-
np.random.randint(-(2
|
|
32
|
+
np.random.randint(0, 2**60, size=1000, dtype="u8").view("M8[ns]"),
|
|
33
|
+
np.random.randint(0, 2**60, size=1000, dtype="u8").view("m8[ns]"),
|
|
34
|
+
np.random.randint(0, 2**25, size=1000, dtype="u8").view("M8[m]"),
|
|
35
|
+
np.random.randint(0, 2**25, size=1000, dtype="u8").view("m8[m]"),
|
|
36
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view("M8[ns]"),
|
|
37
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view("m8[ns]"),
|
|
38
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view("M8[m]"),
|
|
39
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype="i8").view("m8[m]"),
|
|
40
40
|
]
|
|
41
41
|
|
|
42
42
|
|
numcodecs/tests/test_blosc.py
CHANGED
|
@@ -10,18 +10,18 @@ try:
|
|
|
10
10
|
from numcodecs import blosc
|
|
11
11
|
from numcodecs.blosc import Blosc
|
|
12
12
|
except ImportError: # pragma: no cover
|
|
13
|
-
pytest.skip(
|
|
14
|
-
"numcodecs.blosc not available", allow_module_level=True
|
|
15
|
-
)
|
|
13
|
+
pytest.skip("numcodecs.blosc not available", allow_module_level=True)
|
|
16
14
|
|
|
17
15
|
|
|
18
|
-
from numcodecs.tests.common import (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
from numcodecs.tests.common import (
|
|
17
|
+
check_encode_decode,
|
|
18
|
+
check_encode_decode_partial,
|
|
19
|
+
check_config,
|
|
20
|
+
check_backwards_compatibility,
|
|
21
|
+
check_err_decode_object_buffer,
|
|
22
|
+
check_err_encode_object_buffer,
|
|
23
|
+
check_max_buffer_size,
|
|
24
|
+
)
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
codecs = [
|
|
@@ -54,10 +54,10 @@ arrays = [
|
|
|
54
54
|
np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
|
|
55
55
|
np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
|
|
56
56
|
np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
|
|
57
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').view('M8[ns]'),
|
|
58
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').view('m8[ns]'),
|
|
59
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').view('M8[m]'),
|
|
60
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').view('m8[m]'),
|
|
57
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[ns]'),
|
|
58
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[ns]'),
|
|
59
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
|
|
60
|
+
np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
|
|
61
61
|
]
|
|
62
62
|
|
|
63
63
|
|
|
@@ -79,9 +79,13 @@ def test_encode_decode(array, codec):
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
@pytest.mark.parametrize('codec', codecs)
|
|
82
|
-
@pytest.mark.parametrize(
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
@pytest.mark.parametrize(
|
|
83
|
+
'array',
|
|
84
|
+
[
|
|
85
|
+
pytest.param(x) if len(x.shape) == 1 else pytest.param(x, marks=[pytest.mark.xfail])
|
|
86
|
+
for x in arrays
|
|
87
|
+
],
|
|
88
|
+
)
|
|
85
89
|
def test_partial_decode(codec, array):
|
|
86
90
|
_skip_null(codec)
|
|
87
91
|
check_encode_decode_partial(array, codec)
|
|
@@ -105,8 +109,7 @@ def test_repr():
|
|
|
105
109
|
actual = repr(Blosc(cname='zlib', clevel=9, shuffle=Blosc.BITSHUFFLE, blocksize=512))
|
|
106
110
|
assert expect == actual
|
|
107
111
|
expect = "Blosc(cname='blosclz', clevel=5, shuffle=AUTOSHUFFLE, blocksize=1024)"
|
|
108
|
-
actual = repr(Blosc(cname='blosclz', clevel=5, shuffle=Blosc.AUTOSHUFFLE,
|
|
109
|
-
blocksize=1024))
|
|
112
|
+
actual = repr(Blosc(cname='blosclz', clevel=5, shuffle=Blosc.AUTOSHUFFLE, blocksize=1024))
|
|
110
113
|
assert expect == actual
|
|
111
114
|
|
|
112
115
|
|
numcodecs/tests/test_bz2.py
CHANGED
|
@@ -5,10 +5,14 @@ import numpy as np
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
from numcodecs.bz2 import BZ2
|
|
8
|
-
from numcodecs.tests.common import (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
from numcodecs.tests.common import (
|
|
9
|
+
check_encode_decode,
|
|
10
|
+
check_config,
|
|
11
|
+
check_repr,
|
|
12
|
+
check_backwards_compatibility,
|
|
13
|
+
check_err_decode_object_buffer,
|
|
14
|
+
check_err_encode_object_buffer,
|
|
15
|
+
)
|
|
12
16
|
|
|
13
17
|
|
|
14
18
|
codecs = [
|
|
@@ -32,10 +36,10 @@ arrays = [
|
|
|
32
36
|
np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
|
|
33
37
|
np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
|
|
34
38
|
np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
|
|
35
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').view('M8[ns]'),
|
|
36
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').view('m8[ns]'),
|
|
37
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').view('M8[m]'),
|
|
38
|
-
np.random.randint(-2**63, -2**63 + 20, size=1000, dtype='i8').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]'),
|
|
39
43
|
]
|
|
40
44
|
|
|
41
45
|
|
|
@@ -4,9 +4,12 @@ import pytest
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
from numcodecs.categorize import Categorize
|
|
7
|
-
from numcodecs.tests.common import (
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
from numcodecs.tests.common import (
|
|
8
|
+
check_encode_decode,
|
|
9
|
+
check_config,
|
|
10
|
+
check_backwards_compatibility,
|
|
11
|
+
check_encode_decode_array,
|
|
12
|
+
)
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
labels = ['ƒöõ', 'ßàř', 'ßāẑ', 'ƪùüx']
|
|
@@ -20,7 +23,6 @@ arrays_object = [a.astype(object) for a in arrays]
|
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
def test_encode_decode():
|
|
23
|
-
|
|
24
26
|
# unicode dtype
|
|
25
27
|
for arr in arrays:
|
|
26
28
|
codec = Categorize(labels, dtype=arr.dtype)
|
|
@@ -34,7 +36,6 @@ def test_encode_decode():
|
|
|
34
36
|
|
|
35
37
|
def test_encode():
|
|
36
38
|
for dtype in 'U', object:
|
|
37
|
-
|
|
38
39
|
arr = np.array(['ƒöõ', 'ßàř', 'ƒöõ', 'ßāẑ', 'ƪùüx'], dtype=dtype)
|
|
39
40
|
# miss off quux
|
|
40
41
|
codec = Categorize(labels=labels[:-1], dtype=arr.dtype, astype='u1')
|
|
@@ -61,8 +62,7 @@ def test_config():
|
|
|
61
62
|
def test_repr():
|
|
62
63
|
dtype = '<U3'
|
|
63
64
|
astype = '|u1'
|
|
64
|
-
codec = Categorize(labels=['foo', 'bar', 'baz', 'qux'],
|
|
65
|
-
dtype=dtype, astype=astype)
|
|
65
|
+
codec = Categorize(labels=['foo', 'bar', 'baz', 'qux'], dtype=dtype, astype=astype)
|
|
66
66
|
expect = "Categorize(dtype='<U3', astype='|u1', labels=['foo', 'bar', 'baz', ...])"
|
|
67
67
|
actual = repr(codec)
|
|
68
68
|
assert expect == actual
|
|
@@ -77,11 +77,9 @@ def test_repr():
|
|
|
77
77
|
|
|
78
78
|
def test_backwards_compatibility():
|
|
79
79
|
codec = Categorize(labels=labels, dtype='<U4', astype='u1')
|
|
80
|
-
check_backwards_compatibility(Categorize.codec_id, arrays, [codec],
|
|
81
|
-
prefix='U')
|
|
80
|
+
check_backwards_compatibility(Categorize.codec_id, arrays, [codec], prefix='U')
|
|
82
81
|
codec = Categorize(labels=labels, dtype=object, astype='u1')
|
|
83
|
-
check_backwards_compatibility(Categorize.codec_id, arrays_object,
|
|
84
|
-
[codec], prefix='O')
|
|
82
|
+
check_backwards_compatibility(Categorize.codec_id, arrays_object, [codec], prefix='O')
|
|
85
83
|
|
|
86
84
|
|
|
87
85
|
def test_errors():
|
|
@@ -6,9 +6,13 @@ import pytest
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
from numcodecs.checksum32 import CRC32, Adler32
|
|
9
|
-
from numcodecs.tests.common import (
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
from numcodecs.tests.common import (
|
|
10
|
+
check_encode_decode,
|
|
11
|
+
check_config,
|
|
12
|
+
check_repr,
|
|
13
|
+
check_backwards_compatibility,
|
|
14
|
+
check_err_encode_object_buffer,
|
|
15
|
+
)
|
|
12
16
|
|
|
13
17
|
|
|
14
18
|
# mix of dtypes: integer, float, bool, string
|
|
@@ -19,7 +23,7 @@ arrays = [
|
|
|
19
23
|
np.linspace(1000, 1001, 1000, dtype='f8'),
|
|
20
24
|
np.random.normal(loc=1000, scale=1, size=(100, 10)),
|
|
21
25
|
np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
|
|
22
|
-
np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10)
|
|
26
|
+
np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
|
|
23
27
|
]
|
|
24
28
|
|
|
25
29
|
codecs = [CRC32(), Adler32()]
|
numcodecs/tests/test_compat.py
CHANGED
|
@@ -14,7 +14,7 @@ def test_ensure_text():
|
|
|
14
14
|
b'adsdasdas',
|
|
15
15
|
'adsdasdas',
|
|
16
16
|
np.asarray(memoryview(b'adsdasdas')),
|
|
17
|
-
array.array('B', b'qwertyuiqwertyui')
|
|
17
|
+
array.array('B', b'qwertyuiqwertyui'),
|
|
18
18
|
]
|
|
19
19
|
for buf in bufs:
|
|
20
20
|
b = ensure_text(buf)
|
|
@@ -26,7 +26,7 @@ def test_ensure_bytes():
|
|
|
26
26
|
b'adsdasdas',
|
|
27
27
|
bytes(20),
|
|
28
28
|
np.arange(100),
|
|
29
|
-
array.array('l', b'qwertyuiqwertyui')
|
|
29
|
+
array.array('l', b'qwertyuiqwertyui'),
|
|
30
30
|
]
|
|
31
31
|
for buf in bufs:
|
|
32
32
|
b = ensure_bytes(buf)
|
|
@@ -45,7 +45,7 @@ def test_ensure_contiguous_ndarray_shares_memory():
|
|
|
45
45
|
('f', 8, array.array('d', b'qwertyuiqwertyui')),
|
|
46
46
|
('i', 1, array.array('b', b'qwertyuiqwertyui')),
|
|
47
47
|
('u', 1, array.array('B', b'qwertyuiqwertyui')),
|
|
48
|
-
('u', 1, mmap.mmap(-1, 10))
|
|
48
|
+
('u', 1, mmap.mmap(-1, 10)),
|
|
49
49
|
]
|
|
50
50
|
for expected_kind, expected_itemsize, buf in typed_bufs:
|
|
51
51
|
a = ensure_contiguous_ndarray(buf)
|
|
@@ -59,7 +59,6 @@ def test_ensure_contiguous_ndarray_shares_memory():
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
def test_ensure_bytes_invalid_inputs():
|
|
62
|
-
|
|
63
62
|
# object array not allowed
|
|
64
63
|
a = np.array(['Xin chào thế giới'], dtype=object)
|
|
65
64
|
for e in (a, memoryview(a)):
|
|
@@ -68,7 +67,6 @@ def test_ensure_bytes_invalid_inputs():
|
|
|
68
67
|
|
|
69
68
|
|
|
70
69
|
def test_ensure_contiguous_ndarray_invalid_inputs():
|
|
71
|
-
|
|
72
70
|
# object array not allowed
|
|
73
71
|
a = np.array(['Xin chào thế giới'], dtype=object)
|
|
74
72
|
for e in (a, memoryview(a)):
|
|
@@ -98,16 +96,15 @@ def test_ensure_contiguous_ndarray_writeable():
|
|
|
98
96
|
|
|
99
97
|
def test_ensure_contiguous_ndarray_max_buffer_size():
|
|
100
98
|
for max_buffer_size in (4, 64, 1024):
|
|
101
|
-
ensure_contiguous_ndarray(
|
|
102
|
-
|
|
103
|
-
ensure_contiguous_ndarray(
|
|
104
|
-
np.zeros(max_buffer_size, dtype=np.int8), max_buffer_size)
|
|
99
|
+
ensure_contiguous_ndarray(np.zeros(max_buffer_size - 1, dtype=np.int8), max_buffer_size)
|
|
100
|
+
ensure_contiguous_ndarray(np.zeros(max_buffer_size, dtype=np.int8), max_buffer_size)
|
|
105
101
|
buffers = [
|
|
106
102
|
bytes(b"x" * (max_buffer_size + 1)),
|
|
107
103
|
np.zeros(max_buffer_size + 1, dtype=np.int8),
|
|
108
104
|
np.zeros(max_buffer_size + 2, dtype=np.int8),
|
|
109
105
|
np.zeros(max_buffer_size, dtype=np.int16),
|
|
110
|
-
np.zeros(max_buffer_size, dtype=np.int32)
|
|
106
|
+
np.zeros(max_buffer_size, dtype=np.int32),
|
|
107
|
+
]
|
|
111
108
|
for buf in buffers:
|
|
112
109
|
with pytest.raises(ValueError):
|
|
113
110
|
ensure_contiguous_ndarray(buf, max_buffer_size=max_buffer_size)
|