numcodecs 0.13.0__cp312-cp312-macosx_11_0_arm64.whl → 0.14.0__cp312-cp312-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.

Files changed (72) hide show
  1. numcodecs/__init__.py +11 -11
  2. numcodecs/_shuffle.cpython-312-darwin.so +0 -0
  3. numcodecs/abc.py +4 -5
  4. numcodecs/astype.py +2 -4
  5. numcodecs/bitround.py +2 -2
  6. numcodecs/blosc.cpython-312-darwin.so +0 -0
  7. numcodecs/bz2.py +1 -2
  8. numcodecs/categorize.py +5 -12
  9. numcodecs/checksum32.py +87 -13
  10. numcodecs/compat.py +4 -8
  11. numcodecs/compat_ext.cpython-312-darwin.so +0 -0
  12. numcodecs/delta.py +7 -4
  13. numcodecs/fixedscaleoffset.py +3 -9
  14. numcodecs/fletcher32.cpython-312-darwin.so +0 -0
  15. numcodecs/jenkins.cpython-312-darwin.so +0 -0
  16. numcodecs/json.py +7 -8
  17. numcodecs/lz4.cpython-312-darwin.so +0 -0
  18. numcodecs/lzma.py +7 -11
  19. numcodecs/msgpacks.py +2 -5
  20. numcodecs/ndarray_like.py +5 -5
  21. numcodecs/packbits.py +0 -4
  22. numcodecs/pcodec.py +2 -2
  23. numcodecs/pickles.py +1 -1
  24. numcodecs/quantize.py +4 -10
  25. numcodecs/registry.py +10 -9
  26. numcodecs/shuffle.py +4 -4
  27. numcodecs/tests/common.py +7 -11
  28. numcodecs/tests/test_astype.py +2 -4
  29. numcodecs/tests/test_base64.py +2 -5
  30. numcodecs/tests/test_bitround.py +3 -4
  31. numcodecs/tests/test_blosc.py +4 -7
  32. numcodecs/tests/test_bz2.py +3 -6
  33. numcodecs/tests/test_categorize.py +3 -5
  34. numcodecs/tests/test_checksum32.py +101 -24
  35. numcodecs/tests/test_compat.py +4 -3
  36. numcodecs/tests/test_delta.py +4 -5
  37. numcodecs/tests/test_entrypoints.py +1 -2
  38. numcodecs/tests/test_entrypoints_backport.py +4 -4
  39. numcodecs/tests/test_fixedscaleoffset.py +16 -11
  40. numcodecs/tests/test_gzip.py +3 -6
  41. numcodecs/tests/test_jenkins.py +33 -33
  42. numcodecs/tests/test_json.py +3 -3
  43. numcodecs/tests/test_lz4.py +3 -6
  44. numcodecs/tests/test_lzma.py +8 -7
  45. numcodecs/tests/test_msgpacks.py +8 -8
  46. numcodecs/tests/test_packbits.py +2 -4
  47. numcodecs/tests/test_pcodec.py +5 -6
  48. numcodecs/tests/test_pickles.py +2 -3
  49. numcodecs/tests/test_quantize.py +3 -6
  50. numcodecs/tests/test_registry.py +14 -12
  51. numcodecs/tests/test_shuffle.py +5 -8
  52. numcodecs/tests/test_vlen_array.py +5 -6
  53. numcodecs/tests/test_vlen_bytes.py +5 -6
  54. numcodecs/tests/test_vlen_utf8.py +5 -8
  55. numcodecs/tests/test_zarr3.py +248 -0
  56. numcodecs/tests/test_zarr3_import.py +13 -0
  57. numcodecs/tests/test_zfpy.py +8 -6
  58. numcodecs/tests/test_zlib.py +4 -7
  59. numcodecs/tests/test_zstd.py +6 -9
  60. numcodecs/version.py +2 -2
  61. numcodecs/vlen.cpython-312-darwin.so +0 -0
  62. numcodecs/zarr3.py +379 -0
  63. numcodecs/zfpy.py +13 -12
  64. numcodecs/zlib.py +1 -2
  65. numcodecs/zstd.cpython-312-darwin.so +0 -0
  66. {numcodecs-0.13.0.dist-info → numcodecs-0.14.0.dist-info}/METADATA +8 -6
  67. numcodecs-0.14.0.dist-info/RECORD +78 -0
  68. {numcodecs-0.13.0.dist-info → numcodecs-0.14.0.dist-info}/WHEEL +1 -1
  69. numcodecs-0.14.0.dist-info/entry_points.txt +22 -0
  70. numcodecs-0.13.0.dist-info/RECORD +0 -74
  71. {numcodecs-0.13.0.dist-info → numcodecs-0.14.0.dist-info}/LICENSE.txt +0 -0
  72. {numcodecs-0.13.0.dist-info → numcodecs-0.14.0.dist-info}/top_level.txt +0 -0
numcodecs/shuffle.py CHANGED
@@ -1,7 +1,8 @@
1
1
  import numpy as np
2
- from .compat import ensure_contiguous_ndarray
3
- from .abc import Codec
2
+
4
3
  from ._shuffle import _doShuffle, _doUnshuffle
4
+ from .abc import Codec
5
+ from .compat import ensure_contiguous_ndarray
5
6
 
6
7
 
7
8
  class Shuffle(Codec):
@@ -57,5 +58,4 @@ class Shuffle(Codec):
57
58
  return out
58
59
 
59
60
  def __repr__(self):
60
- r = '%s(elementsize=%s)' % (type(self).__name__, self.elementsize)
61
- return r
61
+ return f'{type(self).__name__}(elementsize={self.elementsize})'
numcodecs/tests/common.py CHANGED
@@ -3,19 +3,15 @@ import json as _json
3
3
  import os
4
4
  from glob import glob
5
5
 
6
-
7
6
  import numpy as np
8
- from numpy.testing import assert_array_almost_equal, assert_array_equal
9
7
  import pytest
8
+ from numpy.testing import assert_array_almost_equal, assert_array_equal
10
9
 
11
-
10
+ # star import needed for repr tests so eval finds names
11
+ from numcodecs import * # noqa: F403
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
16
- from numcodecs import * # noqa
17
-
18
-
19
15
  greetings = [
20
16
  '¡Hola mundo!',
21
17
  'Hej Världen!',
@@ -200,7 +196,7 @@ def assert_array_items_equal(res, arr):
200
196
  # and values
201
197
  arr = arr.ravel().tolist()
202
198
  res = res.ravel().tolist()
203
- for a, r in zip(arr, res):
199
+ for a, r in zip(arr, res, strict=True):
204
200
  if isinstance(a, np.ndarray):
205
201
  assert_array_equal(a, r)
206
202
  elif a != a:
@@ -258,7 +254,7 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
258
254
 
259
255
  # save fixture data
260
256
  for i, arr in enumerate(arrays):
261
- arr_fn = os.path.join(fixture_dir, 'array.{:02d}.npy'.format(i))
257
+ arr_fn = os.path.join(fixture_dir, f'array.{i:02d}.npy')
262
258
  if not os.path.exists(arr_fn): # pragma: no cover
263
259
  np.save(arr_fn, arr)
264
260
 
@@ -278,7 +274,7 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
278
274
  pytest.skip("codec has been removed")
279
275
 
280
276
  # setup a directory to hold encoded data
281
- codec_dir = os.path.join(fixture_dir, 'codec.{:02d}'.format(j))
277
+ codec_dir = os.path.join(fixture_dir, f'codec.{j:02d}')
282
278
  if not os.path.exists(codec_dir): # pragma: no cover
283
279
  os.makedirs(codec_dir)
284
280
 
@@ -293,7 +289,7 @@ def check_backwards_compatibility(codec_id, arrays, codecs, precision=None, pref
293
289
  config = _json.load(cf)
294
290
  assert codec == get_codec(config)
295
291
 
296
- enc_fn = os.path.join(codec_dir, 'encoded.{:02d}.dat'.format(i))
292
+ enc_fn = os.path.join(codec_dir, f'encoded.{i:02d}.dat')
297
293
 
298
294
  # one time encode and save array
299
295
  if not os.path.exists(enc_fn): # pragma: no cover
@@ -1,16 +1,14 @@
1
1
  import numpy as np
2
2
  from numpy.testing import assert_array_equal
3
3
 
4
-
5
4
  from numcodecs.astype import AsType
6
5
  from numcodecs.tests.common import (
7
- check_encode_decode,
6
+ check_backwards_compatibility,
8
7
  check_config,
8
+ check_encode_decode,
9
9
  check_repr,
10
- check_backwards_compatibility,
11
10
  )
12
11
 
13
-
14
12
  # mix of dtypes: integer, float
15
13
  # mix of shapes: 1D, 2D, 3D
16
14
  # mix of orders: C, F
@@ -1,20 +1,17 @@
1
1
  import itertools
2
2
 
3
-
4
3
  import numpy as np
5
4
  import pytest
6
5
 
7
-
8
6
  from numcodecs.base64 import Base64
9
7
  from numcodecs.tests.common import (
10
- check_encode_decode,
11
- check_repr,
12
8
  check_backwards_compatibility,
9
+ check_encode_decode,
13
10
  check_err_decode_object_buffer,
14
11
  check_err_encode_object_buffer,
12
+ check_repr,
15
13
  )
16
14
 
17
-
18
15
  codecs = [
19
16
  Base64(),
20
17
  ]
@@ -1,5 +1,4 @@
1
1
  import numpy as np
2
-
3
2
  import pytest
4
3
 
5
4
  from numcodecs.bitround import BitRound, max_bits
@@ -25,21 +24,21 @@ def test_round_zero_to_zero(dtype):
25
24
  # Don't understand Milan's original test:
26
25
  # How is it possible to have negative keepbits?
27
26
  # for k in range(-5, 50):
28
- for k in range(0, max_bits[dtype]):
27
+ for k in range(max_bits[dtype]):
29
28
  ar = round(a, k)
30
29
  np.testing.assert_equal(a, ar)
31
30
 
32
31
 
33
32
  def test_round_one_to_one(dtype):
34
33
  a = np.ones((3, 2), dtype=dtype)
35
- for k in range(0, max_bits[dtype]):
34
+ for k in range(max_bits[dtype]):
36
35
  ar = round(a, k)
37
36
  np.testing.assert_equal(a, ar)
38
37
 
39
38
 
40
39
  def test_round_minus_one_to_minus_one(dtype):
41
40
  a = -np.ones((3, 2), dtype=dtype)
42
- for k in range(0, max_bits[dtype]):
41
+ for k in range(max_bits[dtype]):
43
42
  ar = round(a, k)
44
43
  np.testing.assert_equal(a, ar)
45
44
 
@@ -1,11 +1,9 @@
1
1
  from multiprocessing import Pool
2
2
  from multiprocessing.pool import ThreadPool
3
3
 
4
-
5
4
  import numpy as np
6
5
  import pytest
7
6
 
8
-
9
7
  try:
10
8
  from numcodecs import blosc
11
9
  from numcodecs.blosc import Blosc
@@ -14,16 +12,15 @@ except ImportError: # pragma: no cover
14
12
 
15
13
 
16
14
  from numcodecs.tests.common import (
15
+ check_backwards_compatibility,
16
+ check_config,
17
17
  check_encode_decode,
18
18
  check_encode_decode_partial,
19
- check_config,
20
- check_backwards_compatibility,
21
19
  check_err_decode_object_buffer,
22
20
  check_err_encode_object_buffer,
23
21
  check_max_buffer_size,
24
22
  )
25
23
 
26
-
27
24
  codecs = [
28
25
  Blosc(shuffle=Blosc.SHUFFLE),
29
26
  Blosc(clevel=0, shuffle=Blosc.SHUFFLE),
@@ -136,7 +133,7 @@ def test_compress_blocksize_default(use_threads):
136
133
  assert blocksize > 0
137
134
 
138
135
 
139
- @pytest.mark.parametrize('bs', (2**7, 2**8))
136
+ @pytest.mark.parametrize('bs', [2**7, 2**8])
140
137
  def test_compress_blocksize(use_threads, bs):
141
138
  arr = np.arange(1000, dtype='i4')
142
139
 
@@ -228,7 +225,7 @@ def _decode_worker(enc):
228
225
  return data
229
226
 
230
227
 
231
- @pytest.mark.parametrize('pool', (Pool, ThreadPool))
228
+ @pytest.mark.parametrize('pool', [Pool, ThreadPool])
232
229
  def test_multiprocessing(use_threads, pool):
233
230
  data = np.arange(1000000)
234
231
  enc = _encode_worker(data)
@@ -1,20 +1,17 @@
1
1
  import itertools
2
2
 
3
-
4
3
  import numpy as np
5
4
 
6
-
7
5
  from numcodecs.bz2 import BZ2
8
6
  from numcodecs.tests.common import (
9
- check_encode_decode,
10
- check_config,
11
- check_repr,
12
7
  check_backwards_compatibility,
8
+ check_config,
9
+ check_encode_decode,
13
10
  check_err_decode_object_buffer,
14
11
  check_err_encode_object_buffer,
12
+ check_repr,
15
13
  )
16
14
 
17
-
18
15
  codecs = [
19
16
  BZ2(),
20
17
  BZ2(level=1),
@@ -1,17 +1,15 @@
1
1
  import numpy as np
2
- from numpy.testing import assert_array_equal
3
2
  import pytest
4
-
3
+ from numpy.testing import assert_array_equal
5
4
 
6
5
  from numcodecs.categorize import Categorize
7
6
  from numcodecs.tests.common import (
8
- check_encode_decode,
9
- check_config,
10
7
  check_backwards_compatibility,
8
+ check_config,
9
+ check_encode_decode,
11
10
  check_encode_decode_array,
12
11
  )
13
12
 
14
-
15
13
  labels = ['ƒöõ', 'ßàř', 'ßāẑ', 'ƪùüx']
16
14
  arrays = [
17
15
  np.random.choice(labels, size=1000),
@@ -1,20 +1,18 @@
1
1
  import itertools
2
2
 
3
-
4
3
  import numpy as np
5
4
  import pytest
6
5
 
7
-
8
- from numcodecs.checksum32 import CRC32, Adler32
6
+ from numcodecs.checksum32 import CRC32, CRC32C, Adler32
9
7
  from numcodecs.tests.common import (
10
- check_encode_decode,
11
- check_config,
12
- check_repr,
13
8
  check_backwards_compatibility,
9
+ check_config,
10
+ check_encode_decode,
11
+ check_err_decode_object_buffer,
14
12
  check_err_encode_object_buffer,
13
+ check_repr,
15
14
  )
16
15
 
17
-
18
16
  # mix of dtypes: integer, float, bool, string
19
17
  # mix of shapes: 1D, 2D, 3D
20
18
  # mix of orders: C, F
@@ -24,38 +22,117 @@ arrays = [
24
22
  np.random.normal(loc=1000, scale=1, size=(100, 10)),
25
23
  np.random.randint(0, 2, size=1000, dtype=bool).reshape(100, 10, order='F'),
26
24
  np.random.choice([b'a', b'bb', b'ccc'], size=1000).reshape(10, 10, 10),
25
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('M8[ns]'),
26
+ np.random.randint(0, 2**60, size=1000, dtype='u8').view('m8[ns]'),
27
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('M8[m]'),
28
+ np.random.randint(0, 2**25, size=1000, dtype='u8').view('m8[m]'),
29
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[ns]'),
30
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[ns]'),
31
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('M8[m]'),
32
+ np.random.randint(-(2**63), -(2**63) + 20, size=1000, dtype='i8').view('m8[m]'),
33
+ ]
34
+
35
+ codecs = [
36
+ CRC32(),
37
+ CRC32(location="end"),
38
+ CRC32C(location="start"),
39
+ CRC32C(),
40
+ Adler32(),
41
+ Adler32(location="end"),
27
42
  ]
28
43
 
29
- codecs = [CRC32(), Adler32()]
30
44
 
45
+ @pytest.mark.parametrize(("codec", "arr"), itertools.product(codecs, arrays))
46
+ def test_encode_decode(codec, arr):
47
+ check_encode_decode(arr, codec)
48
+
49
+
50
+ @pytest.mark.parametrize(("codec", "arr"), itertools.product(codecs, arrays))
51
+ def test_errors(codec, arr):
52
+ enc = codec.encode(arr)
53
+ with pytest.raises(RuntimeError):
54
+ codec.decode(enc[:-1])
31
55
 
32
- def test_encode_decode():
33
- for codec, arr in itertools.product(codecs, arrays):
34
- check_encode_decode(arr, codec)
35
56
 
57
+ @pytest.mark.parametrize("codec", codecs)
58
+ def test_config(codec):
59
+ check_config(codec)
36
60
 
37
- def test_errors():
38
- for codec, arr in itertools.product(codecs, arrays):
39
- enc = codec.encode(arr)
40
- with pytest.raises(RuntimeError):
41
- codec.decode(enc[:-1])
42
61
 
62
+ @pytest.mark.parametrize("codec", codecs)
63
+ def test_err_input_too_small(codec):
64
+ buf = b'000' # 3 bytes are too little for a 32-bit checksum
65
+ with pytest.raises(ValueError):
66
+ codec.decode(buf)
43
67
 
44
- def test_config():
45
- for codec in codecs:
46
- check_config(codec)
68
+
69
+ @pytest.mark.parametrize("codec", codecs)
70
+ def test_err_encode_non_contiguous(codec):
71
+ # non-contiguous memory
72
+ arr = np.arange(1000, dtype='i4')[::2]
73
+ with pytest.raises(ValueError):
74
+ codec.encode(arr)
75
+
76
+
77
+ @pytest.mark.parametrize("codec", codecs)
78
+ def test_err_encode_list(codec):
79
+ data = ['foo', 'bar', 'baz']
80
+ with pytest.raises(TypeError):
81
+ codec.encode(data)
82
+
83
+
84
+ def test_err_location():
85
+ with pytest.raises(ValueError):
86
+ CRC32(location="foo")
87
+ with pytest.raises(ValueError):
88
+ CRC32C(location="foo")
89
+ with pytest.raises(ValueError):
90
+ Adler32(location="foo")
47
91
 
48
92
 
49
93
  def test_repr():
50
- check_repr("CRC32()")
51
- check_repr("Adler32()")
94
+ check_repr("CRC32(location='start')")
95
+ check_repr("CRC32C(location='start')")
96
+ check_repr("Adler32(location='start')")
97
+ check_repr("CRC32(location='end')")
98
+ check_repr("CRC32C(location='end')")
99
+ check_repr("Adler32(location='end')")
52
100
 
53
101
 
54
102
  def test_backwards_compatibility():
55
103
  check_backwards_compatibility(CRC32.codec_id, arrays, [CRC32()])
56
104
  check_backwards_compatibility(Adler32.codec_id, arrays, [Adler32()])
105
+ check_backwards_compatibility(CRC32C.codec_id, arrays, [CRC32C()])
106
+
107
+
108
+ @pytest.mark.parametrize("codec", codecs)
109
+ def test_err_encode_object_buffer(codec):
110
+ check_err_encode_object_buffer(codec)
111
+
112
+
113
+ @pytest.mark.parametrize("codec", codecs)
114
+ def test_err_decode_object_buffer(codec):
115
+ check_err_decode_object_buffer(codec)
116
+
117
+
118
+ @pytest.mark.parametrize("codec", codecs)
119
+ def test_err_out_too_small(codec):
120
+ arr = np.arange(10, dtype='i4')
121
+ out = np.empty_like(arr)[:-1]
122
+ with pytest.raises(ValueError):
123
+ codec.decode(codec.encode(arr), out)
124
+
125
+
126
+ def test_crc32c_checksum():
127
+ arr = np.arange(0, 64, dtype="uint8")
128
+ buf = CRC32C(location="end").encode(arr)
129
+ assert np.frombuffer(buf, dtype="<u4", offset=(len(buf) - 4))[0] == np.uint32(4218238699)
57
130
 
58
131
 
59
- def test_err_encode_object_buffer():
60
- check_err_encode_object_buffer(CRC32())
61
- check_err_encode_object_buffer(Adler32())
132
+ @pytest.mark.parametrize("codec", codecs)
133
+ def test_err_checksum(codec):
134
+ arr = np.arange(0, 64, dtype="uint8")
135
+ buf = bytearray(codec.encode(arr))
136
+ buf[-1] = 0 # corrupt the checksum
137
+ with pytest.raises(RuntimeError):
138
+ codec.decode(buf)
@@ -1,12 +1,10 @@
1
1
  import array
2
2
  import mmap
3
3
 
4
-
5
4
  import numpy as np
6
5
  import pytest
7
6
 
8
-
9
- from numcodecs.compat import ensure_text, ensure_bytes, ensure_contiguous_ndarray
7
+ from numcodecs.compat import ensure_bytes, ensure_contiguous_ndarray, ensure_text
10
8
 
11
9
 
12
10
  def test_ensure_text():
@@ -66,6 +64,9 @@ def test_ensure_bytes_invalid_inputs():
66
64
  ensure_bytes(e)
67
65
 
68
66
 
67
+ @pytest.mark.filterwarnings(
68
+ "ignore:The 'u' type code is deprecated and will be removed in Python 3.16"
69
+ )
69
70
  def test_ensure_contiguous_ndarray_invalid_inputs():
70
71
  # object array not allowed
71
72
  a = np.array(['Xin chào thế giới'], dtype=object)
@@ -1,21 +1,20 @@
1
1
  import numpy as np
2
- from numpy.testing import assert_array_equal
3
2
  import pytest
4
-
3
+ from numpy.testing import assert_array_equal
5
4
 
6
5
  from numcodecs.delta import Delta
7
6
  from numcodecs.tests.common import (
8
- check_encode_decode,
7
+ check_backwards_compatibility,
9
8
  check_config,
9
+ check_encode_decode,
10
10
  check_repr,
11
- check_backwards_compatibility,
12
11
  )
13
12
 
14
-
15
13
  # mix of dtypes: integer, float
16
14
  # mix of shapes: 1D, 2D, 3D
17
15
  # mix of orders: C, F
18
16
  arrays = [
17
+ np.random.randint(0, 1, size=110, dtype='?').reshape(10, 11),
19
18
  np.arange(1000, dtype='<i4'),
20
19
  np.linspace(1000, 1001, 1000, dtype='<f4').reshape(100, 10),
21
20
  np.random.normal(loc=1000, scale=1, size=(10, 10, 10)).astype('<f8'),
@@ -5,11 +5,10 @@ import pytest
5
5
 
6
6
  import numcodecs.registry
7
7
 
8
-
9
8
  here = os.path.abspath(os.path.dirname(__file__))
10
9
 
11
10
 
12
- @pytest.fixture()
11
+ @pytest.fixture
13
12
  def set_path():
14
13
  sys.path.append(here)
15
14
  numcodecs.registry.run_entrypoints()
@@ -1,14 +1,14 @@
1
+ import importlib.util
1
2
  import os.path
2
- import pkgutil
3
3
  import sys
4
+ from multiprocessing import Process
4
5
 
5
6
  import pytest
6
7
 
7
- from multiprocessing import Process
8
-
9
8
  import numcodecs.registry
10
9
 
11
- if not pkgutil.find_loader("importlib_metadata"): # pragma: no cover
10
+ importlib_spec = importlib.util.find_spec("importlib_metadata")
11
+ if importlib_spec is None or importlib_spec.loader is None: # pragma: no cover
12
12
  pytest.skip(
13
13
  "This test module requires importlib_metadata to be installed",
14
14
  allow_module_level=True,
@@ -1,20 +1,17 @@
1
1
  import itertools
2
2
 
3
-
4
3
  import numpy as np
5
- from numpy.testing import assert_array_equal
6
4
  import pytest
7
-
5
+ from numpy.testing import assert_array_equal
8
6
 
9
7
  from numcodecs.fixedscaleoffset import FixedScaleOffset
10
8
  from numcodecs.tests.common import (
11
- check_encode_decode,
9
+ check_backwards_compatibility,
12
10
  check_config,
11
+ check_encode_decode,
13
12
  check_repr,
14
- check_backwards_compatibility,
15
13
  )
16
14
 
17
-
18
15
  arrays = [
19
16
  np.linspace(1000, 1001, 1000, dtype='<f8'),
20
17
  np.random.normal(loc=1000, scale=1, size=1000).astype('<f8'),
@@ -39,12 +36,20 @@ def test_encode_decode():
39
36
  check_encode_decode(arr, codec, precision=precision)
40
37
 
41
38
 
42
- def test_encode():
39
+ @pytest.mark.parametrize(
40
+ ("offset", "scale", "expected"),
41
+ [
42
+ (1000, 10, [0, 6, 11, 17, 22, 28, 33, 39, 44, 50]),
43
+ (1002.5, 10, [-25, -19, -14, -8, -3, 3, 8, 14, 19, 25]),
44
+ (1000, 0.5, [0, 0, 1, 1, 1, 1, 2, 2, 2, 2]),
45
+ ],
46
+ )
47
+ def test_encode(offset: float, scale: float, expected: list[int]):
43
48
  dtype = '<f8'
44
- astype = '|u1'
45
- codec = FixedScaleOffset(scale=10, offset=1000, dtype=dtype, astype=astype)
46
- arr = np.linspace(1000, 1001, 10, dtype=dtype)
47
- expect = np.array([0, 1, 2, 3, 4, 6, 7, 8, 9, 10], dtype=astype)
49
+ astype = np.int16
50
+ codec = FixedScaleOffset(scale=scale, offset=offset, dtype=dtype, astype=astype)
51
+ arr = np.linspace(1000, 1005, 10, dtype=dtype)
52
+ expect = np.array(expected, dtype=astype)
48
53
  actual = codec.encode(arr)
49
54
  assert_array_equal(expect, actual)
50
55
  assert np.dtype(astype) == actual.dtype
@@ -1,21 +1,18 @@
1
1
  import itertools
2
2
 
3
-
4
3
  import numpy as np
5
4
  import pytest
6
5
 
7
-
8
6
  from numcodecs.gzip import GZip
9
7
  from numcodecs.tests.common import (
10
- check_encode_decode,
11
- check_config,
12
- check_repr,
13
8
  check_backwards_compatibility,
9
+ check_config,
10
+ check_encode_decode,
14
11
  check_err_decode_object_buffer,
15
12
  check_err_encode_object_buffer,
13
+ check_repr,
16
14
  )
17
15
 
18
-
19
16
  codecs = [
20
17
  GZip(),
21
18
  GZip(level=-1),
@@ -1,8 +1,8 @@
1
1
  import numpy as np
2
2
  import pytest
3
3
 
4
- from numcodecs.jenkins import jenkins_lookup3
5
4
  from numcodecs.checksum32 import JenkinsLookup3
5
+ from numcodecs.jenkins import jenkins_lookup3
6
6
 
7
7
 
8
8
  def test_jenkins_lookup3():
@@ -84,38 +84,38 @@ def test_jenkins_lookup3_codec():
84
84
 
85
85
  chunk_index = (
86
86
  b"\x00\x08\x00\x00\x00\x00\x00\x00"
87
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
88
- + b"\xf7\x17\x00\x00\x00\x00\x00\x00"
89
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
90
- + b"\xee'\x00\x00\x00\x00\x00\x00"
91
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
92
- + b"\xe57\x00\x00\x00\x00\x00\x00"
93
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
94
- + b"\xdcG\x00\x00\x00\x00\x00\x00"
95
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
96
- + b"\xd3W\x00\x00\x00\x00\x00\x00"
97
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
98
- + b"\xcag\x00\x00\x00\x00\x00\x00"
99
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
100
- + b"\xc1w\x00\x00\x00\x00\x00\x00"
101
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
102
- + b"\xb8\x87\x00\x00\x00\x00\x00\x00"
103
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
104
- + b"\xaf\x97\x00\x00\x00\x00\x00\x00"
105
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
106
- + b"\xa6\xa7\x00\x00\x00\x00\x00\x00"
107
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
108
- + b"\x9d\xb7\x00\x00\x00\x00\x00\x00"
109
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
110
- + b"\x94\xc7\x00\x00\x00\x00\x00\x00"
111
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
112
- + b"\x8b\xd7\x00\x00\x00\x00\x00\x00"
113
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
114
- + b"\x82\xe7\x00\x00\x00\x00\x00\x00"
115
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
116
- + b"y\xf7\x00\x00\x00\x00\x00\x00"
117
- + b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
118
- + b"n\x96\x07\x85"
87
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
88
+ b"\xf7\x17\x00\x00\x00\x00\x00\x00"
89
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
90
+ b"\xee'\x00\x00\x00\x00\x00\x00"
91
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
92
+ b"\xe57\x00\x00\x00\x00\x00\x00"
93
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
94
+ b"\xdcG\x00\x00\x00\x00\x00\x00"
95
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
96
+ b"\xd3W\x00\x00\x00\x00\x00\x00"
97
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
98
+ b"\xcag\x00\x00\x00\x00\x00\x00"
99
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
100
+ b"\xc1w\x00\x00\x00\x00\x00\x00"
101
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
102
+ b"\xb8\x87\x00\x00\x00\x00\x00\x00"
103
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
104
+ b"\xaf\x97\x00\x00\x00\x00\x00\x00"
105
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
106
+ b"\xa6\xa7\x00\x00\x00\x00\x00\x00"
107
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
108
+ b"\x9d\xb7\x00\x00\x00\x00\x00\x00"
109
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
110
+ b"\x94\xc7\x00\x00\x00\x00\x00\x00"
111
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
112
+ b"\x8b\xd7\x00\x00\x00\x00\x00\x00"
113
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
114
+ b"\x82\xe7\x00\x00\x00\x00\x00\x00"
115
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
116
+ b"y\xf7\x00\x00\x00\x00\x00\x00"
117
+ b"\xf7\x0f\x00\x00\x00\x00\x00\x00"
118
+ b"n\x96\x07\x85"
119
119
  )
120
120
  hdf5_fadb_prefix = b'FADB\x00\x01\xcf\x01\x00\x00\x00\x00\x00\x00'
121
121
  j = JenkinsLookup3(prefix=hdf5_fadb_prefix)
@@ -5,10 +5,10 @@ import pytest
5
5
 
6
6
  from numcodecs.json import JSON
7
7
  from numcodecs.tests.common import (
8
+ check_backwards_compatibility,
8
9
  check_config,
9
- check_repr,
10
10
  check_encode_decode_array,
11
- check_backwards_compatibility,
11
+ check_repr,
12
12
  greetings,
13
13
  )
14
14
 
@@ -59,7 +59,7 @@ def test_backwards_compatibility():
59
59
 
60
60
 
61
61
  @pytest.mark.parametrize(
62
- "input_data, dtype",
62
+ ('input_data', 'dtype'),
63
63
  [
64
64
  ([0, 1], None),
65
65
  ([[0, 1], [2, 3]], None),