numcodecs 0.12.1__cp311-cp311-macosx_10_9_x86_64.whl → 0.13.0__cp311-cp311-macosx_10_9_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 +29 -1
- numcodecs/_shuffle.cpython-311-darwin.so +0 -0
- numcodecs/abc.py +5 -5
- 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_backport.py +5 -1
- 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.1.dist-info → numcodecs-0.13.0.dist-info}/METADATA +6 -3
- numcodecs-0.13.0.dist-info/RECORD +74 -0
- {numcodecs-0.12.1.dist-info → numcodecs-0.13.0.dist-info}/WHEEL +1 -1
- numcodecs-0.12.1.dist-info/RECORD +0 -72
- {numcodecs-0.12.1.dist-info → numcodecs-0.13.0.dist-info}/LICENSE.txt +0 -0
- {numcodecs-0.12.1.dist-info → numcodecs-0.13.0.dist-info}/top_level.txt +0 -0
numcodecs/__init__.py
CHANGED
|
@@ -13,9 +13,10 @@ pipelines in a variety of ways.
|
|
|
13
13
|
|
|
14
14
|
If you have a question, find a bug, would like to make a suggestion or
|
|
15
15
|
contribute code, please `raise an issue on GitHub
|
|
16
|
-
<https://github.com/
|
|
16
|
+
<https://github.com/zarr-developers/numcodecs/issues>`_.
|
|
17
17
|
|
|
18
18
|
"""
|
|
19
|
+
|
|
19
20
|
import multiprocessing
|
|
20
21
|
import atexit
|
|
21
22
|
from contextlib import suppress
|
|
@@ -25,21 +26,26 @@ from numcodecs.version import version as __version__
|
|
|
25
26
|
from numcodecs.registry import get_codec, register_codec
|
|
26
27
|
|
|
27
28
|
from numcodecs.zlib import Zlib
|
|
29
|
+
|
|
28
30
|
register_codec(Zlib)
|
|
29
31
|
|
|
30
32
|
from numcodecs.gzip import GZip
|
|
33
|
+
|
|
31
34
|
register_codec(GZip)
|
|
32
35
|
|
|
33
36
|
from numcodecs.bz2 import BZ2
|
|
37
|
+
|
|
34
38
|
register_codec(BZ2)
|
|
35
39
|
|
|
36
40
|
with suppress(ImportError):
|
|
37
41
|
from numcodecs.lzma import LZMA
|
|
42
|
+
|
|
38
43
|
register_codec(LZMA)
|
|
39
44
|
|
|
40
45
|
with suppress(ImportError):
|
|
41
46
|
from numcodecs import blosc
|
|
42
47
|
from numcodecs.blosc import Blosc
|
|
48
|
+
|
|
43
49
|
register_codec(Blosc)
|
|
44
50
|
# initialize blosc
|
|
45
51
|
try:
|
|
@@ -53,65 +59,87 @@ with suppress(ImportError):
|
|
|
53
59
|
with suppress(ImportError):
|
|
54
60
|
from numcodecs import zstd
|
|
55
61
|
from numcodecs.zstd import Zstd
|
|
62
|
+
|
|
56
63
|
register_codec(Zstd)
|
|
57
64
|
|
|
58
65
|
with suppress(ImportError):
|
|
59
66
|
from numcodecs import lz4
|
|
60
67
|
from numcodecs.lz4 import LZ4
|
|
68
|
+
|
|
61
69
|
register_codec(LZ4)
|
|
62
70
|
|
|
63
71
|
with suppress(ImportError):
|
|
64
72
|
from numcodecs.zfpy import ZFPY
|
|
73
|
+
|
|
65
74
|
register_codec(ZFPY)
|
|
66
75
|
|
|
67
76
|
from numcodecs.astype import AsType
|
|
77
|
+
|
|
68
78
|
register_codec(AsType)
|
|
69
79
|
|
|
70
80
|
from numcodecs.delta import Delta
|
|
81
|
+
|
|
71
82
|
register_codec(Delta)
|
|
72
83
|
|
|
73
84
|
from numcodecs.quantize import Quantize
|
|
85
|
+
|
|
74
86
|
register_codec(Quantize)
|
|
75
87
|
|
|
76
88
|
from numcodecs.fixedscaleoffset import FixedScaleOffset
|
|
89
|
+
|
|
77
90
|
register_codec(FixedScaleOffset)
|
|
78
91
|
|
|
79
92
|
from numcodecs.packbits import PackBits
|
|
93
|
+
|
|
80
94
|
register_codec(PackBits)
|
|
81
95
|
|
|
82
96
|
from numcodecs.categorize import Categorize
|
|
97
|
+
|
|
83
98
|
register_codec(Categorize)
|
|
84
99
|
|
|
85
100
|
from numcodecs.pickles import Pickle
|
|
101
|
+
|
|
86
102
|
register_codec(Pickle)
|
|
87
103
|
|
|
88
104
|
from numcodecs.base64 import Base64
|
|
105
|
+
|
|
89
106
|
register_codec(Base64)
|
|
90
107
|
|
|
91
108
|
from numcodecs.shuffle import Shuffle
|
|
109
|
+
|
|
92
110
|
register_codec(Shuffle)
|
|
93
111
|
|
|
94
112
|
from numcodecs.bitround import BitRound
|
|
113
|
+
|
|
95
114
|
register_codec(BitRound)
|
|
96
115
|
|
|
97
116
|
with suppress(ImportError):
|
|
98
117
|
from numcodecs.msgpacks import MsgPack
|
|
118
|
+
|
|
99
119
|
register_codec(MsgPack)
|
|
100
120
|
|
|
101
121
|
from numcodecs.checksum32 import CRC32, Adler32, JenkinsLookup3
|
|
122
|
+
|
|
102
123
|
register_codec(CRC32)
|
|
103
124
|
register_codec(Adler32)
|
|
104
125
|
register_codec(JenkinsLookup3)
|
|
105
126
|
|
|
106
127
|
from numcodecs.json import JSON
|
|
128
|
+
|
|
107
129
|
register_codec(JSON)
|
|
108
130
|
|
|
109
131
|
with suppress(ImportError):
|
|
110
132
|
from numcodecs import vlen
|
|
111
133
|
from numcodecs.vlen import VLenUTF8, VLenBytes, VLenArray
|
|
134
|
+
|
|
112
135
|
register_codec(VLenUTF8)
|
|
113
136
|
register_codec(VLenBytes)
|
|
114
137
|
register_codec(VLenArray)
|
|
115
138
|
|
|
116
139
|
from numcodecs.fletcher32 import Fletcher32
|
|
140
|
+
|
|
117
141
|
register_codec(Fletcher32)
|
|
142
|
+
|
|
143
|
+
from numcodecs.pcodec import PCodec
|
|
144
|
+
|
|
145
|
+
register_codec(PCodec)
|
|
Binary file
|
numcodecs/abc.py
CHANGED
|
@@ -28,7 +28,6 @@ other and vice versa.
|
|
|
28
28
|
|
|
29
29
|
"""
|
|
30
30
|
|
|
31
|
-
|
|
32
31
|
from abc import ABC, abstractmethod
|
|
33
32
|
|
|
34
33
|
|
|
@@ -114,15 +113,16 @@ class Codec(ABC):
|
|
|
114
113
|
return False
|
|
115
114
|
|
|
116
115
|
def __repr__(self):
|
|
117
|
-
|
|
118
116
|
# override in sub-class if need special representation
|
|
119
117
|
|
|
120
118
|
# by default, assume all non-private members are configuration
|
|
121
119
|
# parameters and valid keyword arguments to constructor function
|
|
122
120
|
|
|
123
121
|
r = '%s(' % type(self).__name__
|
|
124
|
-
params = [
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
params = [
|
|
123
|
+
'{}={!r}'.format(k, getattr(self, k))
|
|
124
|
+
for k in sorted(self.__dict__)
|
|
125
|
+
if not k.startswith('_')
|
|
126
|
+
]
|
|
127
127
|
r += ', '.join(params) + ')'
|
|
128
128
|
return r
|
numcodecs/astype.py
CHANGED
|
@@ -45,7 +45,6 @@ class AsType(Codec):
|
|
|
45
45
|
self.decode_dtype = np.dtype(decode_dtype)
|
|
46
46
|
|
|
47
47
|
def encode(self, buf):
|
|
48
|
-
|
|
49
48
|
# normalise input
|
|
50
49
|
arr = ensure_ndarray(buf).view(self.decode_dtype)
|
|
51
50
|
|
|
@@ -55,7 +54,6 @@ class AsType(Codec):
|
|
|
55
54
|
return enc
|
|
56
55
|
|
|
57
56
|
def decode(self, buf, out=None):
|
|
58
|
-
|
|
59
57
|
# normalise input
|
|
60
58
|
enc = ensure_ndarray(buf).view(self.encode_dtype)
|
|
61
59
|
|
|
@@ -75,10 +73,6 @@ class AsType(Codec):
|
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
def __repr__(self):
|
|
78
|
-
return (
|
|
79
|
-
|
|
80
|
-
type(self).__name__,
|
|
81
|
-
self.encode_dtype.str,
|
|
82
|
-
self.decode_dtype.str
|
|
83
|
-
)
|
|
76
|
+
return '{}(encode_dtype={!r}, decode_dtype={!r})'.format(
|
|
77
|
+
type(self).__name__, self.encode_dtype.str, self.decode_dtype.str
|
|
84
78
|
)
|
|
Binary file
|
numcodecs/bz2.py
CHANGED
|
@@ -21,7 +21,6 @@ class BZ2(Codec):
|
|
|
21
21
|
self.level = level
|
|
22
22
|
|
|
23
23
|
def encode(self, buf):
|
|
24
|
-
|
|
25
24
|
# normalise input
|
|
26
25
|
buf = ensure_contiguous_ndarray(buf)
|
|
27
26
|
|
|
@@ -30,7 +29,6 @@ class BZ2(Codec):
|
|
|
30
29
|
|
|
31
30
|
# noinspection PyMethodMayBeStatic
|
|
32
31
|
def decode(self, buf, out=None):
|
|
33
|
-
|
|
34
32
|
# normalise inputs
|
|
35
33
|
buf = ensure_contiguous_ndarray(buf)
|
|
36
34
|
if out is not None:
|
numcodecs/categorize.py
CHANGED
|
@@ -41,17 +41,15 @@ class Categorize(Codec):
|
|
|
41
41
|
def __init__(self, labels, dtype, astype='u1'):
|
|
42
42
|
self.dtype = np.dtype(dtype)
|
|
43
43
|
if self.dtype.kind not in 'UO':
|
|
44
|
-
raise TypeError("only unicode ('U') and object ('O') dtypes are "
|
|
45
|
-
"supported")
|
|
44
|
+
raise TypeError("only unicode ('U') and object ('O') dtypes are " "supported")
|
|
46
45
|
self.labels = [ensure_text(label) for label in labels]
|
|
47
46
|
self.astype = np.dtype(astype)
|
|
48
|
-
if self.astype == object:
|
|
47
|
+
if self.astype == np.dtype(object):
|
|
49
48
|
raise TypeError('encoding as object array not supported')
|
|
50
49
|
|
|
51
50
|
def encode(self, buf):
|
|
52
|
-
|
|
53
51
|
# normalise input
|
|
54
|
-
if self.dtype == object:
|
|
52
|
+
if self.dtype == np.dtype(object):
|
|
55
53
|
arr = np.asarray(buf, dtype=object)
|
|
56
54
|
else:
|
|
57
55
|
arr = ensure_ndarray(buf).view(self.dtype)
|
|
@@ -63,13 +61,12 @@ class Categorize(Codec):
|
|
|
63
61
|
enc = np.zeros_like(arr, dtype=self.astype)
|
|
64
62
|
|
|
65
63
|
# apply encoding, reserving 0 for values not specified in labels
|
|
66
|
-
for i,
|
|
67
|
-
enc[arr ==
|
|
64
|
+
for i, label in enumerate(self.labels):
|
|
65
|
+
enc[arr == label] = i + 1
|
|
68
66
|
|
|
69
67
|
return enc
|
|
70
68
|
|
|
71
69
|
def decode(self, buf, out=None):
|
|
72
|
-
|
|
73
70
|
# normalise input
|
|
74
71
|
enc = ensure_ndarray(buf).view(self.astype)
|
|
75
72
|
|
|
@@ -80,8 +77,8 @@ class Categorize(Codec):
|
|
|
80
77
|
dec = np.full_like(enc, fill_value='', dtype=self.dtype)
|
|
81
78
|
|
|
82
79
|
# apply decoding
|
|
83
|
-
for i,
|
|
84
|
-
dec[enc == (i + 1)] =
|
|
80
|
+
for i, label in enumerate(self.labels):
|
|
81
|
+
dec[enc == (i + 1)] = label
|
|
85
82
|
|
|
86
83
|
# handle output
|
|
87
84
|
dec = ndarray_copy(dec, out)
|
|
@@ -93,7 +90,7 @@ class Categorize(Codec):
|
|
|
93
90
|
id=self.codec_id,
|
|
94
91
|
labels=self.labels,
|
|
95
92
|
dtype=self.dtype.str,
|
|
96
|
-
astype=self.astype.str
|
|
93
|
+
astype=self.astype.str,
|
|
97
94
|
)
|
|
98
95
|
return config
|
|
99
96
|
|
|
@@ -102,6 +99,10 @@ class Categorize(Codec):
|
|
|
102
99
|
labels = repr(self.labels[:3])
|
|
103
100
|
if len(self.labels) > 3:
|
|
104
101
|
labels = labels[:-1] + ', ...]'
|
|
105
|
-
r = '%s(dtype=%r, astype=%r, labels=%s)' %
|
|
106
|
-
|
|
102
|
+
r = '%s(dtype=%r, astype=%r, labels=%s)' % (
|
|
103
|
+
type(self).__name__,
|
|
104
|
+
self.dtype.str,
|
|
105
|
+
self.astype.str,
|
|
106
|
+
labels,
|
|
107
|
+
)
|
|
107
108
|
return r
|
numcodecs/checksum32.py
CHANGED
|
@@ -11,13 +11,12 @@ from .jenkins import jenkins_lookup3
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class Checksum32(Codec):
|
|
14
|
-
|
|
15
14
|
# override in sub-class
|
|
16
15
|
checksum = None
|
|
17
16
|
|
|
18
17
|
def encode(self, buf):
|
|
19
18
|
arr = ensure_contiguous_ndarray(buf).view('u1')
|
|
20
|
-
checksum = self.checksum(arr) &
|
|
19
|
+
checksum = self.checksum(arr) & 0xFFFFFFFF
|
|
21
20
|
enc = np.empty(arr.nbytes + 4, dtype='u1')
|
|
22
21
|
enc[:4].view('<u4')[0] = checksum
|
|
23
22
|
ndarray_copy(arr, enc[4:])
|
|
@@ -26,20 +25,18 @@ class Checksum32(Codec):
|
|
|
26
25
|
def decode(self, buf, out=None):
|
|
27
26
|
arr = ensure_contiguous_ndarray(buf).view('u1')
|
|
28
27
|
expect = arr[:4].view('<u4')[0]
|
|
29
|
-
checksum = self.checksum(arr[4:]) &
|
|
28
|
+
checksum = self.checksum(arr[4:]) & 0xFFFFFFFF
|
|
30
29
|
if expect != checksum:
|
|
31
30
|
raise RuntimeError('checksum failed')
|
|
32
31
|
return ndarray_copy(arr[4:], out)
|
|
33
32
|
|
|
34
33
|
|
|
35
34
|
class CRC32(Checksum32):
|
|
36
|
-
|
|
37
35
|
codec_id = 'crc32'
|
|
38
36
|
checksum = zlib.crc32
|
|
39
37
|
|
|
40
38
|
|
|
41
39
|
class Adler32(Checksum32):
|
|
42
|
-
|
|
43
40
|
codec_id = 'adler32'
|
|
44
41
|
checksum = zlib.adler32
|
|
45
42
|
|
numcodecs/compat.py
CHANGED
|
@@ -67,9 +67,7 @@ def ensure_ndarray(buf) -> np.ndarray:
|
|
|
67
67
|
return np.array(ensure_ndarray_like(buf), copy=False)
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def ensure_contiguous_ndarray_like(
|
|
71
|
-
buf, max_buffer_size=None, flatten=True
|
|
72
|
-
) -> NDArrayLike:
|
|
70
|
+
def ensure_contiguous_ndarray_like(buf, max_buffer_size=None, flatten=True) -> NDArrayLike:
|
|
73
71
|
"""Convenience function to coerce `buf` to ndarray-like array.
|
|
74
72
|
Also ensures that the returned value exports fully contiguous memory,
|
|
75
73
|
and supports the new-style buffer interface. If the optional max_buffer_size is
|
|
@@ -152,9 +150,7 @@ def ensure_contiguous_ndarray(buf, max_buffer_size=None, flatten=True) -> np.arr
|
|
|
152
150
|
"""
|
|
153
151
|
|
|
154
152
|
return ensure_ndarray(
|
|
155
|
-
ensure_contiguous_ndarray_like(
|
|
156
|
-
buf, max_buffer_size=max_buffer_size, flatten=flatten
|
|
157
|
-
)
|
|
153
|
+
ensure_contiguous_ndarray_like(buf, max_buffer_size=max_buffer_size, flatten=flatten)
|
|
158
154
|
)
|
|
159
155
|
|
|
160
156
|
|
|
Binary file
|
numcodecs/delta.py
CHANGED
|
@@ -47,11 +47,10 @@ class Delta(Codec):
|
|
|
47
47
|
self.astype = self.dtype
|
|
48
48
|
else:
|
|
49
49
|
self.astype = np.dtype(astype)
|
|
50
|
-
if self.dtype == object or self.astype == object:
|
|
50
|
+
if self.dtype == np.dtype(object) or self.astype == np.dtype(object):
|
|
51
51
|
raise ValueError('object arrays are not supported')
|
|
52
52
|
|
|
53
53
|
def encode(self, buf):
|
|
54
|
-
|
|
55
54
|
# normalise input
|
|
56
55
|
arr = ensure_ndarray(buf).view(self.dtype)
|
|
57
56
|
|
|
@@ -70,7 +69,6 @@ class Delta(Codec):
|
|
|
70
69
|
return enc
|
|
71
70
|
|
|
72
71
|
def decode(self, buf, out=None):
|
|
73
|
-
|
|
74
72
|
# normalise input
|
|
75
73
|
enc = ensure_ndarray(buf).view(self.astype)
|
|
76
74
|
|
|
@@ -90,11 +88,7 @@ class Delta(Codec):
|
|
|
90
88
|
|
|
91
89
|
def get_config(self):
|
|
92
90
|
# override to handle encoding dtypes
|
|
93
|
-
return dict(
|
|
94
|
-
id=self.codec_id,
|
|
95
|
-
dtype=self.dtype.str,
|
|
96
|
-
astype=self.astype.str
|
|
97
|
-
)
|
|
91
|
+
return dict(id=self.codec_id, dtype=self.dtype.str, astype=self.astype.str)
|
|
98
92
|
|
|
99
93
|
def __repr__(self):
|
|
100
94
|
r = '{}(dtype={!r}'.format(type(self).__name__, self.dtype.str)
|
numcodecs/fixedscaleoffset.py
CHANGED
|
@@ -78,11 +78,10 @@ class FixedScaleOffset(Codec):
|
|
|
78
78
|
self.astype = self.dtype
|
|
79
79
|
else:
|
|
80
80
|
self.astype = np.dtype(astype)
|
|
81
|
-
if self.dtype == object or self.astype == object:
|
|
81
|
+
if self.dtype == np.dtype(object) or self.astype == np.dtype(object):
|
|
82
82
|
raise ValueError('object arrays are not supported')
|
|
83
83
|
|
|
84
84
|
def encode(self, buf):
|
|
85
|
-
|
|
86
85
|
# normalise input
|
|
87
86
|
arr = ensure_ndarray(buf).view(self.dtype)
|
|
88
87
|
|
|
@@ -101,7 +100,6 @@ class FixedScaleOffset(Codec):
|
|
|
101
100
|
return enc
|
|
102
101
|
|
|
103
102
|
def decode(self, buf, out=None):
|
|
104
|
-
|
|
105
103
|
# interpret buffer as numpy array
|
|
106
104
|
enc = ensure_ndarray(buf).view(self.astype)
|
|
107
105
|
|
|
@@ -124,12 +122,16 @@ class FixedScaleOffset(Codec):
|
|
|
124
122
|
scale=self.scale,
|
|
125
123
|
offset=self.offset,
|
|
126
124
|
dtype=self.dtype.str,
|
|
127
|
-
astype=self.astype.str
|
|
125
|
+
astype=self.astype.str,
|
|
128
126
|
)
|
|
129
127
|
|
|
130
128
|
def __repr__(self):
|
|
131
|
-
r = '%s(scale=%s, offset=%s, dtype=%r' %
|
|
132
|
-
|
|
129
|
+
r = '%s(scale=%s, offset=%s, dtype=%r' % (
|
|
130
|
+
type(self).__name__,
|
|
131
|
+
self.scale,
|
|
132
|
+
self.offset,
|
|
133
|
+
self.dtype.str,
|
|
134
|
+
)
|
|
133
135
|
if self.astype != self.dtype:
|
|
134
136
|
r += ', astype=%r' % self.astype.str
|
|
135
137
|
r += ')'
|
|
Binary file
|
numcodecs/gzip.py
CHANGED
|
@@ -21,15 +21,12 @@ class GZip(Codec):
|
|
|
21
21
|
self.level = level
|
|
22
22
|
|
|
23
23
|
def encode(self, buf):
|
|
24
|
-
|
|
25
24
|
# normalise inputs
|
|
26
25
|
buf = ensure_contiguous_ndarray(buf)
|
|
27
26
|
|
|
28
27
|
# do compression
|
|
29
28
|
compressed = io.BytesIO()
|
|
30
|
-
with _gzip.GzipFile(fileobj=compressed,
|
|
31
|
-
mode='wb',
|
|
32
|
-
compresslevel=self.level) as compressor:
|
|
29
|
+
with _gzip.GzipFile(fileobj=compressed, mode='wb', compresslevel=self.level) as compressor:
|
|
33
30
|
compressor.write(buf)
|
|
34
31
|
compressed = compressed.getvalue()
|
|
35
32
|
|
|
@@ -37,7 +34,6 @@ class GZip(Codec):
|
|
|
37
34
|
|
|
38
35
|
# noinspection PyMethodMayBeStatic
|
|
39
36
|
def decode(self, buf, out=None):
|
|
40
|
-
|
|
41
37
|
# normalise inputs
|
|
42
38
|
# BytesIO only copies if the data is not of `bytes` type.
|
|
43
39
|
# This allows `bytes` objects to pass through without copying.
|
|
Binary file
|
numcodecs/json.py
CHANGED
|
@@ -33,9 +33,18 @@ class JSON(Codec):
|
|
|
33
33
|
|
|
34
34
|
codec_id = 'json2'
|
|
35
35
|
|
|
36
|
-
def __init__(
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
encoding='utf-8',
|
|
39
|
+
skipkeys=False,
|
|
40
|
+
ensure_ascii=True,
|
|
41
|
+
check_circular=True,
|
|
42
|
+
allow_nan=True,
|
|
43
|
+
sort_keys=True,
|
|
44
|
+
indent=None,
|
|
45
|
+
separators=None,
|
|
46
|
+
strict=True,
|
|
47
|
+
):
|
|
39
48
|
self._text_encoding = encoding
|
|
40
49
|
if separators is None:
|
|
41
50
|
# ensure separators are explicitly specified, and consistent behaviour across
|
|
@@ -45,10 +54,15 @@ class JSON(Codec):
|
|
|
45
54
|
else:
|
|
46
55
|
separators = ', ', ': '
|
|
47
56
|
separators = tuple(separators)
|
|
48
|
-
self._encoder_config = dict(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
self._encoder_config = dict(
|
|
58
|
+
skipkeys=skipkeys,
|
|
59
|
+
ensure_ascii=ensure_ascii,
|
|
60
|
+
check_circular=check_circular,
|
|
61
|
+
allow_nan=allow_nan,
|
|
62
|
+
indent=indent,
|
|
63
|
+
separators=separators,
|
|
64
|
+
sort_keys=sort_keys,
|
|
65
|
+
)
|
|
52
66
|
self._encoder = _json.JSONEncoder(**self._encoder_config)
|
|
53
67
|
self._decoder_config = dict(strict=strict)
|
|
54
68
|
self._decoder = _json.JSONDecoder(**self._decoder_config)
|
|
@@ -58,14 +72,18 @@ class JSON(Codec):
|
|
|
58
72
|
buf = np.asarray(buf)
|
|
59
73
|
except ValueError:
|
|
60
74
|
buf = np.asarray(buf, dtype=object)
|
|
61
|
-
items = buf.tolist()
|
|
62
|
-
items.
|
|
75
|
+
items = np.atleast_1d(buf).tolist()
|
|
76
|
+
items.append(buf.dtype.str)
|
|
77
|
+
items.append(buf.shape)
|
|
63
78
|
return self._encoder.encode(items).encode(self._text_encoding)
|
|
64
79
|
|
|
65
80
|
def decode(self, buf, out=None):
|
|
66
81
|
items = self._decoder.decode(ensure_text(buf, self._text_encoding))
|
|
67
82
|
dec = np.empty(items[-1], dtype=items[-2])
|
|
68
|
-
|
|
83
|
+
if not items[-1]:
|
|
84
|
+
dec[...] = items[0]
|
|
85
|
+
else:
|
|
86
|
+
dec[:] = items[:-2]
|
|
69
87
|
if out is not None:
|
|
70
88
|
np.copyto(out, dec)
|
|
71
89
|
return out
|
|
Binary file
|
numcodecs/lzma.py
CHANGED
|
@@ -9,7 +9,6 @@ except ImportError: # pragma: no cover
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
if _lzma:
|
|
12
|
-
|
|
13
12
|
from .abc import Codec
|
|
14
13
|
from .compat import ndarray_copy, ensure_contiguous_ndarray
|
|
15
14
|
|
|
@@ -42,16 +41,19 @@ if _lzma:
|
|
|
42
41
|
self.filters = filters
|
|
43
42
|
|
|
44
43
|
def encode(self, buf):
|
|
45
|
-
|
|
46
44
|
# normalise inputs
|
|
47
45
|
buf = ensure_contiguous_ndarray(buf)
|
|
48
46
|
|
|
49
47
|
# do compression
|
|
50
|
-
return _lzma.compress(
|
|
51
|
-
|
|
48
|
+
return _lzma.compress(
|
|
49
|
+
buf,
|
|
50
|
+
format=self.format,
|
|
51
|
+
check=self.check,
|
|
52
|
+
preset=self.preset,
|
|
53
|
+
filters=self.filters,
|
|
54
|
+
)
|
|
52
55
|
|
|
53
56
|
def decode(self, buf, out=None):
|
|
54
|
-
|
|
55
57
|
# normalise inputs
|
|
56
58
|
buf = ensure_contiguous_ndarray(buf)
|
|
57
59
|
if out is not None:
|
|
@@ -64,7 +66,11 @@ if _lzma:
|
|
|
64
66
|
return ndarray_copy(dec, out)
|
|
65
67
|
|
|
66
68
|
def __repr__(self):
|
|
67
|
-
r = '%s(format=%r, check=%r, preset=%r, filters=%r)' %
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
r = '%s(format=%r, check=%r, preset=%r, filters=%r)' % (
|
|
70
|
+
type(self).__name__,
|
|
71
|
+
self.format,
|
|
72
|
+
self.check,
|
|
73
|
+
self.preset,
|
|
74
|
+
self.filters,
|
|
75
|
+
)
|
|
70
76
|
return r
|
numcodecs/msgpacks.py
CHANGED
|
@@ -58,8 +58,11 @@ class MsgPack(Codec):
|
|
|
58
58
|
buf = np.asarray(buf, dtype=object)
|
|
59
59
|
items = buf.tolist()
|
|
60
60
|
items.extend((buf.dtype.str, buf.shape))
|
|
61
|
-
return msgpack.packb(
|
|
62
|
-
|
|
61
|
+
return msgpack.packb(
|
|
62
|
+
items,
|
|
63
|
+
use_bin_type=self.use_bin_type,
|
|
64
|
+
use_single_float=self.use_single_float,
|
|
65
|
+
)
|
|
63
66
|
|
|
64
67
|
def decode(self, buf, out=None):
|
|
65
68
|
buf = ensure_contiguous_ndarray(buf)
|
|
@@ -73,13 +76,14 @@ class MsgPack(Codec):
|
|
|
73
76
|
return dec
|
|
74
77
|
|
|
75
78
|
def get_config(self):
|
|
76
|
-
return dict(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
return dict(
|
|
80
|
+
id=self.codec_id,
|
|
81
|
+
raw=self.raw,
|
|
82
|
+
use_single_float=self.use_single_float,
|
|
83
|
+
use_bin_type=self.use_bin_type,
|
|
84
|
+
)
|
|
80
85
|
|
|
81
86
|
def __repr__(self):
|
|
82
|
-
return (
|
|
83
|
-
|
|
84
|
-
.format(self.raw, self.use_bin_type, self.use_single_float)
|
|
87
|
+
return 'MsgPack(raw={!r}, use_bin_type={!r}, use_single_float={!r})'.format(
|
|
88
|
+
self.raw, self.use_bin_type, self.use_single_float
|
|
85
89
|
)
|
numcodecs/ndarray_like.py
CHANGED
|
@@ -10,6 +10,7 @@ class _CachedProtocolMeta(Protocol.__class__):
|
|
|
10
10
|
This metaclass keeps an unbounded cache of the result of
|
|
11
11
|
isinstance checks using the object's class as the cache key.
|
|
12
12
|
"""
|
|
13
|
+
|
|
13
14
|
_instancecheck_cache: Dict[Tuple[Type, Type], bool] = {}
|
|
14
15
|
|
|
15
16
|
def __instancecheck__(self, instance):
|
|
@@ -46,23 +47,17 @@ class NDArrayLike(Protocol, metaclass=_CachedProtocolMeta):
|
|
|
46
47
|
nbytes: int
|
|
47
48
|
flags: FlagsObj
|
|
48
49
|
|
|
49
|
-
def __len__(self) -> int:
|
|
50
|
-
... # pragma: no cover
|
|
50
|
+
def __len__(self) -> int: ... # pragma: no cover
|
|
51
51
|
|
|
52
|
-
def __getitem__(self, key) -> Any:
|
|
53
|
-
... # pragma: no cover
|
|
52
|
+
def __getitem__(self, key) -> Any: ... # pragma: no cover
|
|
54
53
|
|
|
55
|
-
def __setitem__(self, key, value):
|
|
56
|
-
... # pragma: no cover
|
|
54
|
+
def __setitem__(self, key, value): ... # pragma: no cover
|
|
57
55
|
|
|
58
|
-
def tobytes(self, order: Optional[str] = ...) -> bytes:
|
|
59
|
-
... # pragma: no cover
|
|
56
|
+
def tobytes(self, order: Optional[str] = ...) -> bytes: ... # pragma: no cover
|
|
60
57
|
|
|
61
|
-
def reshape(self, *shape: int, order: str = ...) -> "NDArrayLike":
|
|
62
|
-
... # pragma: no cover
|
|
58
|
+
def reshape(self, *shape: int, order: str = ...) -> "NDArrayLike": ... # pragma: no cover
|
|
63
59
|
|
|
64
|
-
def view(self, dtype: DType = ...) -> "NDArrayLike":
|
|
65
|
-
... # pragma: no cover
|
|
60
|
+
def view(self, dtype: DType = ...) -> "NDArrayLike": ... # pragma: no cover
|
|
66
61
|
|
|
67
62
|
|
|
68
63
|
def is_ndarray_like(obj: object) -> bool:
|
numcodecs/packbits.py
CHANGED
|
@@ -34,7 +34,6 @@ class PackBits(Codec):
|
|
|
34
34
|
pass
|
|
35
35
|
|
|
36
36
|
def encode(self, buf):
|
|
37
|
-
|
|
38
37
|
# normalise input
|
|
39
38
|
arr = ensure_ndarray(buf).view(bool)
|
|
40
39
|
|
|
@@ -43,7 +42,7 @@ class PackBits(Codec):
|
|
|
43
42
|
|
|
44
43
|
# determine size of packed data
|
|
45
44
|
n = arr.size
|
|
46
|
-
n_bytes_packed =
|
|
45
|
+
n_bytes_packed = n // 8
|
|
47
46
|
n_bits_leftover = n % 8
|
|
48
47
|
if n_bits_leftover > 0:
|
|
49
48
|
n_bytes_packed += 1
|
|
@@ -64,7 +63,6 @@ class PackBits(Codec):
|
|
|
64
63
|
return enc
|
|
65
64
|
|
|
66
65
|
def decode(self, buf, out=None):
|
|
67
|
-
|
|
68
66
|
# normalise input
|
|
69
67
|
enc = ensure_ndarray(buf).view('u1')
|
|
70
68
|
|