numcodecs 0.12.1__cp311-cp311-win_amd64.whl → 0.13.1__cp311-cp311-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of numcodecs might be problematic. Click here for more details.
- numcodecs/__init__.py +33 -7
- numcodecs/_shuffle.cp311-win_amd64.pyd +0 -0
- numcodecs/abc.py +4 -6
- numcodecs/astype.py +2 -10
- numcodecs/bitround.py +0 -1
- numcodecs/blosc.cp311-win_amd64.pyd +0 -0
- numcodecs/bz2.py +1 -4
- numcodecs/categorize.py +12 -18
- numcodecs/checksum32.py +3 -8
- numcodecs/compat.py +6 -12
- numcodecs/compat_ext.cp311-win_amd64.pyd +0 -0
- numcodecs/delta.py +4 -11
- numcodecs/fixedscaleoffset.py +5 -9
- numcodecs/fletcher32.cp311-win_amd64.pyd +0 -0
- numcodecs/gzip.py +1 -5
- numcodecs/jenkins.cp311-win_amd64.pyd +0 -0
- numcodecs/json.py +35 -18
- numcodecs/lz4.cp311-win_amd64.pyd +0 -0
- numcodecs/lzma.py +9 -10
- numcodecs/msgpacks.py +13 -12
- numcodecs/ndarray_like.py +11 -16
- numcodecs/packbits.py +1 -4
- numcodecs/pcodec.py +89 -0
- numcodecs/pickles.py +2 -3
- numcodecs/quantize.py +7 -11
- numcodecs/registry.py +4 -8
- numcodecs/shuffle.py +5 -7
- numcodecs/tests/common.py +42 -32
- numcodecs/tests/package_with_entrypoint/__init__.py +0 -1
- numcodecs/tests/test_astype.py +7 -7
- numcodecs/tests/test_base64.py +10 -13
- numcodecs/tests/test_bitround.py +0 -1
- numcodecs/tests/test_blosc.py +22 -22
- numcodecs/tests/test_bz2.py +12 -11
- numcodecs/tests/test_categorize.py +10 -14
- numcodecs/tests/test_checksum32.py +8 -7
- numcodecs/tests/test_compat.py +8 -13
- numcodecs/tests/test_delta.py +7 -5
- numcodecs/tests/test_entrypoints.py +0 -1
- numcodecs/tests/test_entrypoints_backport.py +8 -5
- numcodecs/tests/test_fixedscaleoffset.py +7 -6
- numcodecs/tests/test_fletcher32.py +13 -6
- numcodecs/tests/test_gzip.py +12 -11
- numcodecs/tests/test_jenkins.py +41 -42
- numcodecs/tests/test_json.py +17 -7
- numcodecs/tests/test_lz4.py +14 -15
- numcodecs/tests/test_lzma.py +15 -14
- numcodecs/tests/test_msgpacks.py +10 -8
- numcodecs/tests/test_packbits.py +6 -4
- numcodecs/tests/test_pcodec.py +80 -0
- numcodecs/tests/test_pickles.py +11 -8
- numcodecs/tests/test_quantize.py +7 -6
- numcodecs/tests/test_registry.py +4 -4
- numcodecs/tests/test_shuffle.py +34 -26
- numcodecs/tests/test_vlen_array.py +14 -16
- numcodecs/tests/test_vlen_bytes.py +13 -8
- numcodecs/tests/test_vlen_utf8.py +14 -9
- numcodecs/tests/test_zfpy.py +7 -17
- numcodecs/tests/test_zlib.py +12 -11
- numcodecs/tests/test_zstd.py +32 -16
- numcodecs/version.py +2 -2
- numcodecs/vlen.cp311-win_amd64.pyd +0 -0
- numcodecs/zfpy.py +35 -20
- numcodecs/zlib.py +1 -4
- numcodecs/zstd.cp311-win_amd64.pyd +0 -0
- {numcodecs-0.12.1.dist-info → numcodecs-0.13.1.dist-info}/METADATA +8 -5
- numcodecs-0.13.1.dist-info/RECORD +74 -0
- {numcodecs-0.12.1.dist-info → numcodecs-0.13.1.dist-info}/WHEEL +1 -1
- numcodecs-0.12.1.dist-info/RECORD +0 -72
- {numcodecs-0.12.1.dist-info → numcodecs-0.13.1.dist-info}/LICENSE.txt +0 -0
- {numcodecs-0.12.1.dist-info → numcodecs-0.13.1.dist-info}/top_level.txt +0 -0
numcodecs/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ruff: noqa: E402,F401
|
|
2
2
|
"""Numcodecs is a Python package providing buffer compression and
|
|
3
3
|
transformation codecs for use in data storage and communication
|
|
4
4
|
applications. These include:
|
|
@@ -13,33 +13,37 @@ 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
20
|
import atexit
|
|
21
|
+
import multiprocessing
|
|
21
22
|
from contextlib import suppress
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
from numcodecs.version import version as __version__
|
|
25
24
|
from numcodecs.registry import get_codec, register_codec
|
|
26
|
-
|
|
25
|
+
from numcodecs.version import version as __version__
|
|
27
26
|
from numcodecs.zlib import Zlib
|
|
27
|
+
|
|
28
28
|
register_codec(Zlib)
|
|
29
29
|
|
|
30
30
|
from numcodecs.gzip import GZip
|
|
31
|
+
|
|
31
32
|
register_codec(GZip)
|
|
32
33
|
|
|
33
34
|
from numcodecs.bz2 import BZ2
|
|
35
|
+
|
|
34
36
|
register_codec(BZ2)
|
|
35
37
|
|
|
36
38
|
with suppress(ImportError):
|
|
37
39
|
from numcodecs.lzma import LZMA
|
|
40
|
+
|
|
38
41
|
register_codec(LZMA)
|
|
39
42
|
|
|
40
43
|
with suppress(ImportError):
|
|
41
44
|
from numcodecs import blosc
|
|
42
45
|
from numcodecs.blosc import Blosc
|
|
46
|
+
|
|
43
47
|
register_codec(Blosc)
|
|
44
48
|
# initialize blosc
|
|
45
49
|
try:
|
|
@@ -53,65 +57,87 @@ with suppress(ImportError):
|
|
|
53
57
|
with suppress(ImportError):
|
|
54
58
|
from numcodecs import zstd
|
|
55
59
|
from numcodecs.zstd import Zstd
|
|
60
|
+
|
|
56
61
|
register_codec(Zstd)
|
|
57
62
|
|
|
58
63
|
with suppress(ImportError):
|
|
59
64
|
from numcodecs import lz4
|
|
60
65
|
from numcodecs.lz4 import LZ4
|
|
66
|
+
|
|
61
67
|
register_codec(LZ4)
|
|
62
68
|
|
|
63
69
|
with suppress(ImportError):
|
|
64
70
|
from numcodecs.zfpy import ZFPY
|
|
71
|
+
|
|
65
72
|
register_codec(ZFPY)
|
|
66
73
|
|
|
67
74
|
from numcodecs.astype import AsType
|
|
75
|
+
|
|
68
76
|
register_codec(AsType)
|
|
69
77
|
|
|
70
78
|
from numcodecs.delta import Delta
|
|
79
|
+
|
|
71
80
|
register_codec(Delta)
|
|
72
81
|
|
|
73
82
|
from numcodecs.quantize import Quantize
|
|
83
|
+
|
|
74
84
|
register_codec(Quantize)
|
|
75
85
|
|
|
76
86
|
from numcodecs.fixedscaleoffset import FixedScaleOffset
|
|
87
|
+
|
|
77
88
|
register_codec(FixedScaleOffset)
|
|
78
89
|
|
|
79
90
|
from numcodecs.packbits import PackBits
|
|
91
|
+
|
|
80
92
|
register_codec(PackBits)
|
|
81
93
|
|
|
82
94
|
from numcodecs.categorize import Categorize
|
|
95
|
+
|
|
83
96
|
register_codec(Categorize)
|
|
84
97
|
|
|
85
98
|
from numcodecs.pickles import Pickle
|
|
99
|
+
|
|
86
100
|
register_codec(Pickle)
|
|
87
101
|
|
|
88
102
|
from numcodecs.base64 import Base64
|
|
103
|
+
|
|
89
104
|
register_codec(Base64)
|
|
90
105
|
|
|
91
106
|
from numcodecs.shuffle import Shuffle
|
|
107
|
+
|
|
92
108
|
register_codec(Shuffle)
|
|
93
109
|
|
|
94
110
|
from numcodecs.bitround import BitRound
|
|
111
|
+
|
|
95
112
|
register_codec(BitRound)
|
|
96
113
|
|
|
97
114
|
with suppress(ImportError):
|
|
98
115
|
from numcodecs.msgpacks import MsgPack
|
|
116
|
+
|
|
99
117
|
register_codec(MsgPack)
|
|
100
118
|
|
|
101
119
|
from numcodecs.checksum32 import CRC32, Adler32, JenkinsLookup3
|
|
120
|
+
|
|
102
121
|
register_codec(CRC32)
|
|
103
122
|
register_codec(Adler32)
|
|
104
123
|
register_codec(JenkinsLookup3)
|
|
105
124
|
|
|
106
125
|
from numcodecs.json import JSON
|
|
126
|
+
|
|
107
127
|
register_codec(JSON)
|
|
108
128
|
|
|
109
129
|
with suppress(ImportError):
|
|
110
130
|
from numcodecs import vlen
|
|
111
|
-
from numcodecs.vlen import
|
|
131
|
+
from numcodecs.vlen import VLenArray, VLenBytes, VLenUTF8
|
|
132
|
+
|
|
112
133
|
register_codec(VLenUTF8)
|
|
113
134
|
register_codec(VLenBytes)
|
|
114
135
|
register_codec(VLenArray)
|
|
115
136
|
|
|
116
137
|
from numcodecs.fletcher32 import Fletcher32
|
|
138
|
+
|
|
117
139
|
register_codec(Fletcher32)
|
|
140
|
+
|
|
141
|
+
from numcodecs.pcodec import PCodec
|
|
142
|
+
|
|
143
|
+
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,14 @@ 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
|
-
r = '
|
|
124
|
-
params = [
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
r = f'{type(self).__name__}('
|
|
122
|
+
params = [
|
|
123
|
+
f'{k}={getattr(self, k)!r}' for k in sorted(self.__dict__) if not k.startswith('_')
|
|
124
|
+
]
|
|
127
125
|
r += ', '.join(params) + ')'
|
|
128
126
|
return r
|
numcodecs/astype.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
|
|
3
3
|
from .abc import Codec
|
|
4
|
-
from .compat import
|
|
4
|
+
from .compat import ensure_ndarray, ndarray_copy
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class AsType(Codec):
|
|
@@ -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,4 @@ class AsType(Codec):
|
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
def __repr__(self):
|
|
78
|
-
return (
|
|
79
|
-
'{}(encode_dtype={!r}, decode_dtype={!r})'.format(
|
|
80
|
-
type(self).__name__,
|
|
81
|
-
self.encode_dtype.str,
|
|
82
|
-
self.decode_dtype.str
|
|
83
|
-
)
|
|
84
|
-
)
|
|
76
|
+
return f'{type(self).__name__}(encode_dtype={self.encode_dtype.str!r}, decode_dtype={self.decode_dtype.str!r})'
|
numcodecs/bitround.py
CHANGED
|
Binary file
|
numcodecs/bz2.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import bz2 as _bz2
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
from numcodecs.abc import Codec
|
|
5
|
-
from numcodecs.compat import
|
|
4
|
+
from numcodecs.compat import ensure_contiguous_ndarray, ndarray_copy
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
class BZ2(Codec):
|
|
@@ -21,7 +20,6 @@ class BZ2(Codec):
|
|
|
21
20
|
self.level = level
|
|
22
21
|
|
|
23
22
|
def encode(self, buf):
|
|
24
|
-
|
|
25
23
|
# normalise input
|
|
26
24
|
buf = ensure_contiguous_ndarray(buf)
|
|
27
25
|
|
|
@@ -30,7 +28,6 @@ class BZ2(Codec):
|
|
|
30
28
|
|
|
31
29
|
# noinspection PyMethodMayBeStatic
|
|
32
30
|
def decode(self, buf, out=None):
|
|
33
|
-
|
|
34
31
|
# normalise inputs
|
|
35
32
|
buf = ensure_contiguous_ndarray(buf)
|
|
36
33
|
if out is not None:
|
numcodecs/categorize.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
from .abc import Codec
|
|
2
|
-
from .compat import ensure_ndarray, ndarray_copy, ensure_text
|
|
3
|
-
|
|
4
|
-
|
|
5
1
|
import numpy as np
|
|
6
2
|
|
|
3
|
+
from .abc import Codec
|
|
4
|
+
from .compat import ensure_ndarray, ensure_text, ndarray_copy
|
|
5
|
+
|
|
7
6
|
|
|
8
7
|
class Categorize(Codec):
|
|
9
8
|
"""Filter encoding categorical string data as integers.
|
|
@@ -41,17 +40,15 @@ class Categorize(Codec):
|
|
|
41
40
|
def __init__(self, labels, dtype, astype='u1'):
|
|
42
41
|
self.dtype = np.dtype(dtype)
|
|
43
42
|
if self.dtype.kind not in 'UO':
|
|
44
|
-
raise TypeError("only unicode ('U') and object ('O') dtypes are "
|
|
45
|
-
"supported")
|
|
43
|
+
raise TypeError("only unicode ('U') and object ('O') dtypes are supported")
|
|
46
44
|
self.labels = [ensure_text(label) for label in labels]
|
|
47
45
|
self.astype = np.dtype(astype)
|
|
48
|
-
if self.astype == object:
|
|
46
|
+
if self.astype == np.dtype(object):
|
|
49
47
|
raise TypeError('encoding as object array not supported')
|
|
50
48
|
|
|
51
49
|
def encode(self, buf):
|
|
52
|
-
|
|
53
50
|
# normalise input
|
|
54
|
-
if self.dtype == object:
|
|
51
|
+
if self.dtype == np.dtype(object):
|
|
55
52
|
arr = np.asarray(buf, dtype=object)
|
|
56
53
|
else:
|
|
57
54
|
arr = ensure_ndarray(buf).view(self.dtype)
|
|
@@ -63,13 +60,12 @@ class Categorize(Codec):
|
|
|
63
60
|
enc = np.zeros_like(arr, dtype=self.astype)
|
|
64
61
|
|
|
65
62
|
# apply encoding, reserving 0 for values not specified in labels
|
|
66
|
-
for i,
|
|
67
|
-
enc[arr ==
|
|
63
|
+
for i, label in enumerate(self.labels):
|
|
64
|
+
enc[arr == label] = i + 1
|
|
68
65
|
|
|
69
66
|
return enc
|
|
70
67
|
|
|
71
68
|
def decode(self, buf, out=None):
|
|
72
|
-
|
|
73
69
|
# normalise input
|
|
74
70
|
enc = ensure_ndarray(buf).view(self.astype)
|
|
75
71
|
|
|
@@ -80,8 +76,8 @@ class Categorize(Codec):
|
|
|
80
76
|
dec = np.full_like(enc, fill_value='', dtype=self.dtype)
|
|
81
77
|
|
|
82
78
|
# apply decoding
|
|
83
|
-
for i,
|
|
84
|
-
dec[enc == (i + 1)] =
|
|
79
|
+
for i, label in enumerate(self.labels):
|
|
80
|
+
dec[enc == (i + 1)] = label
|
|
85
81
|
|
|
86
82
|
# handle output
|
|
87
83
|
dec = ndarray_copy(dec, out)
|
|
@@ -93,7 +89,7 @@ class Categorize(Codec):
|
|
|
93
89
|
id=self.codec_id,
|
|
94
90
|
labels=self.labels,
|
|
95
91
|
dtype=self.dtype.str,
|
|
96
|
-
astype=self.astype.str
|
|
92
|
+
astype=self.astype.str,
|
|
97
93
|
)
|
|
98
94
|
return config
|
|
99
95
|
|
|
@@ -102,6 +98,4 @@ class Categorize(Codec):
|
|
|
102
98
|
labels = repr(self.labels[:3])
|
|
103
99
|
if len(self.labels) > 3:
|
|
104
100
|
labels = labels[:-1] + ', ...]'
|
|
105
|
-
|
|
106
|
-
(type(self).__name__, self.dtype.str, self.astype.str, labels)
|
|
107
|
-
return r
|
|
101
|
+
return f'{type(self).__name__}(dtype={self.dtype.str!r}, astype={self.astype.str!r}, labels={labels})'
|
numcodecs/checksum32.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import struct
|
|
1
2
|
import zlib
|
|
2
3
|
|
|
3
|
-
|
|
4
4
|
import numpy as np
|
|
5
|
-
import struct
|
|
6
|
-
|
|
7
5
|
|
|
8
6
|
from .abc import Codec
|
|
9
7
|
from .compat import ensure_contiguous_ndarray, ndarray_copy
|
|
@@ -11,13 +9,12 @@ from .jenkins import jenkins_lookup3
|
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
class Checksum32(Codec):
|
|
14
|
-
|
|
15
12
|
# override in sub-class
|
|
16
13
|
checksum = None
|
|
17
14
|
|
|
18
15
|
def encode(self, buf):
|
|
19
16
|
arr = ensure_contiguous_ndarray(buf).view('u1')
|
|
20
|
-
checksum = self.checksum(arr) &
|
|
17
|
+
checksum = self.checksum(arr) & 0xFFFFFFFF
|
|
21
18
|
enc = np.empty(arr.nbytes + 4, dtype='u1')
|
|
22
19
|
enc[:4].view('<u4')[0] = checksum
|
|
23
20
|
ndarray_copy(arr, enc[4:])
|
|
@@ -26,20 +23,18 @@ class Checksum32(Codec):
|
|
|
26
23
|
def decode(self, buf, out=None):
|
|
27
24
|
arr = ensure_contiguous_ndarray(buf).view('u1')
|
|
28
25
|
expect = arr[:4].view('<u4')[0]
|
|
29
|
-
checksum = self.checksum(arr[4:]) &
|
|
26
|
+
checksum = self.checksum(arr[4:]) & 0xFFFFFFFF
|
|
30
27
|
if expect != checksum:
|
|
31
28
|
raise RuntimeError('checksum failed')
|
|
32
29
|
return ndarray_copy(arr[4:], out)
|
|
33
30
|
|
|
34
31
|
|
|
35
32
|
class CRC32(Checksum32):
|
|
36
|
-
|
|
37
33
|
codec_id = 'crc32'
|
|
38
34
|
checksum = zlib.crc32
|
|
39
35
|
|
|
40
36
|
|
|
41
37
|
class Adler32(Checksum32):
|
|
42
|
-
|
|
43
38
|
codec_id = 'adler32'
|
|
44
39
|
checksum = zlib.adler32
|
|
45
40
|
|
numcodecs/compat.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
import functools
|
|
3
|
-
import sys
|
|
4
|
-
import codecs
|
|
1
|
+
# ruff: noqa: F401
|
|
5
2
|
import array
|
|
6
|
-
|
|
3
|
+
import codecs
|
|
4
|
+
import functools
|
|
7
5
|
|
|
8
6
|
import numpy as np
|
|
9
7
|
|
|
@@ -67,9 +65,7 @@ def ensure_ndarray(buf) -> np.ndarray:
|
|
|
67
65
|
return np.array(ensure_ndarray_like(buf), copy=False)
|
|
68
66
|
|
|
69
67
|
|
|
70
|
-
def ensure_contiguous_ndarray_like(
|
|
71
|
-
buf, max_buffer_size=None, flatten=True
|
|
72
|
-
) -> NDArrayLike:
|
|
68
|
+
def ensure_contiguous_ndarray_like(buf, max_buffer_size=None, flatten=True) -> NDArrayLike:
|
|
73
69
|
"""Convenience function to coerce `buf` to ndarray-like array.
|
|
74
70
|
Also ensures that the returned value exports fully contiguous memory,
|
|
75
71
|
and supports the new-style buffer interface. If the optional max_buffer_size is
|
|
@@ -117,7 +113,7 @@ def ensure_contiguous_ndarray_like(
|
|
|
117
113
|
raise ValueError("an array with contiguous memory is required")
|
|
118
114
|
|
|
119
115
|
if max_buffer_size is not None and arr.nbytes > max_buffer_size:
|
|
120
|
-
msg = "Codec does not support buffers of > {} bytes"
|
|
116
|
+
msg = f"Codec does not support buffers of > {max_buffer_size} bytes"
|
|
121
117
|
raise ValueError(msg)
|
|
122
118
|
|
|
123
119
|
return arr
|
|
@@ -152,9 +148,7 @@ def ensure_contiguous_ndarray(buf, max_buffer_size=None, flatten=True) -> np.arr
|
|
|
152
148
|
"""
|
|
153
149
|
|
|
154
150
|
return ensure_ndarray(
|
|
155
|
-
ensure_contiguous_ndarray_like(
|
|
156
|
-
buf, max_buffer_size=max_buffer_size, flatten=flatten
|
|
157
|
-
)
|
|
151
|
+
ensure_contiguous_ndarray_like(buf, max_buffer_size=max_buffer_size, flatten=flatten)
|
|
158
152
|
)
|
|
159
153
|
|
|
160
154
|
|
|
Binary file
|
numcodecs/delta.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
from .abc import Codec
|
|
5
4
|
from .compat import ensure_ndarray, ndarray_copy
|
|
6
5
|
|
|
@@ -47,11 +46,10 @@ class Delta(Codec):
|
|
|
47
46
|
self.astype = self.dtype
|
|
48
47
|
else:
|
|
49
48
|
self.astype = np.dtype(astype)
|
|
50
|
-
if self.dtype == object or self.astype == object:
|
|
49
|
+
if self.dtype == np.dtype(object) or self.astype == np.dtype(object):
|
|
51
50
|
raise ValueError('object arrays are not supported')
|
|
52
51
|
|
|
53
52
|
def encode(self, buf):
|
|
54
|
-
|
|
55
53
|
# normalise input
|
|
56
54
|
arr = ensure_ndarray(buf).view(self.dtype)
|
|
57
55
|
|
|
@@ -70,7 +68,6 @@ class Delta(Codec):
|
|
|
70
68
|
return enc
|
|
71
69
|
|
|
72
70
|
def decode(self, buf, out=None):
|
|
73
|
-
|
|
74
71
|
# normalise input
|
|
75
72
|
enc = ensure_ndarray(buf).view(self.astype)
|
|
76
73
|
|
|
@@ -90,15 +87,11 @@ class Delta(Codec):
|
|
|
90
87
|
|
|
91
88
|
def get_config(self):
|
|
92
89
|
# override to handle encoding dtypes
|
|
93
|
-
return dict(
|
|
94
|
-
id=self.codec_id,
|
|
95
|
-
dtype=self.dtype.str,
|
|
96
|
-
astype=self.astype.str
|
|
97
|
-
)
|
|
90
|
+
return dict(id=self.codec_id, dtype=self.dtype.str, astype=self.astype.str)
|
|
98
91
|
|
|
99
92
|
def __repr__(self):
|
|
100
|
-
r = '{
|
|
93
|
+
r = f'{type(self).__name__}(dtype={self.dtype.str!r}'
|
|
101
94
|
if self.astype != self.dtype:
|
|
102
|
-
r += ', astype
|
|
95
|
+
r += f', astype={self.astype.str!r}'
|
|
103
96
|
r += ')'
|
|
104
97
|
return r
|
numcodecs/fixedscaleoffset.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
from .abc import Codec
|
|
5
4
|
from .compat import ensure_ndarray, ndarray_copy
|
|
6
5
|
|
|
@@ -15,7 +14,7 @@ class FixedScaleOffset(Codec):
|
|
|
15
14
|
----------
|
|
16
15
|
offset : float
|
|
17
16
|
Value to subtract from data.
|
|
18
|
-
scale :
|
|
17
|
+
scale : float
|
|
19
18
|
Value to multiply by data.
|
|
20
19
|
dtype : dtype
|
|
21
20
|
Data type to use for decoded data.
|
|
@@ -78,11 +77,10 @@ class FixedScaleOffset(Codec):
|
|
|
78
77
|
self.astype = self.dtype
|
|
79
78
|
else:
|
|
80
79
|
self.astype = np.dtype(astype)
|
|
81
|
-
if self.dtype == object or self.astype == object:
|
|
80
|
+
if self.dtype == np.dtype(object) or self.astype == np.dtype(object):
|
|
82
81
|
raise ValueError('object arrays are not supported')
|
|
83
82
|
|
|
84
83
|
def encode(self, buf):
|
|
85
|
-
|
|
86
84
|
# normalise input
|
|
87
85
|
arr = ensure_ndarray(buf).view(self.dtype)
|
|
88
86
|
|
|
@@ -101,7 +99,6 @@ class FixedScaleOffset(Codec):
|
|
|
101
99
|
return enc
|
|
102
100
|
|
|
103
101
|
def decode(self, buf, out=None):
|
|
104
|
-
|
|
105
102
|
# interpret buffer as numpy array
|
|
106
103
|
enc = ensure_ndarray(buf).view(self.astype)
|
|
107
104
|
|
|
@@ -124,13 +121,12 @@ class FixedScaleOffset(Codec):
|
|
|
124
121
|
scale=self.scale,
|
|
125
122
|
offset=self.offset,
|
|
126
123
|
dtype=self.dtype.str,
|
|
127
|
-
astype=self.astype.str
|
|
124
|
+
astype=self.astype.str,
|
|
128
125
|
)
|
|
129
126
|
|
|
130
127
|
def __repr__(self):
|
|
131
|
-
r = '
|
|
132
|
-
(type(self).__name__, self.scale, self.offset, self.dtype.str)
|
|
128
|
+
r = f'{type(self).__name__}(scale={self.scale}, offset={self.offset}, dtype={self.dtype.str!r}'
|
|
133
129
|
if self.astype != self.dtype:
|
|
134
|
-
r += ', astype
|
|
130
|
+
r += f', astype={self.astype.str!r}'
|
|
135
131
|
r += ')'
|
|
136
132
|
return 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
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import json as _json
|
|
2
2
|
import textwrap
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
import numpy as np
|
|
6
5
|
|
|
7
|
-
|
|
8
6
|
from .abc import Codec
|
|
9
7
|
from .compat import ensure_text
|
|
10
8
|
|
|
@@ -33,9 +31,18 @@ class JSON(Codec):
|
|
|
33
31
|
|
|
34
32
|
codec_id = 'json2'
|
|
35
33
|
|
|
36
|
-
def __init__(
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
encoding='utf-8',
|
|
37
|
+
skipkeys=False,
|
|
38
|
+
ensure_ascii=True,
|
|
39
|
+
check_circular=True,
|
|
40
|
+
allow_nan=True,
|
|
41
|
+
sort_keys=True,
|
|
42
|
+
indent=None,
|
|
43
|
+
separators=None,
|
|
44
|
+
strict=True,
|
|
45
|
+
):
|
|
39
46
|
self._text_encoding = encoding
|
|
40
47
|
if separators is None:
|
|
41
48
|
# ensure separators are explicitly specified, and consistent behaviour across
|
|
@@ -45,10 +52,15 @@ class JSON(Codec):
|
|
|
45
52
|
else:
|
|
46
53
|
separators = ', ', ': '
|
|
47
54
|
separators = tuple(separators)
|
|
48
|
-
self._encoder_config = dict(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
self._encoder_config = dict(
|
|
56
|
+
skipkeys=skipkeys,
|
|
57
|
+
ensure_ascii=ensure_ascii,
|
|
58
|
+
check_circular=check_circular,
|
|
59
|
+
allow_nan=allow_nan,
|
|
60
|
+
indent=indent,
|
|
61
|
+
separators=separators,
|
|
62
|
+
sort_keys=sort_keys,
|
|
63
|
+
)
|
|
52
64
|
self._encoder = _json.JSONEncoder(**self._encoder_config)
|
|
53
65
|
self._decoder_config = dict(strict=strict)
|
|
54
66
|
self._decoder = _json.JSONDecoder(**self._decoder_config)
|
|
@@ -58,14 +70,18 @@ class JSON(Codec):
|
|
|
58
70
|
buf = np.asarray(buf)
|
|
59
71
|
except ValueError:
|
|
60
72
|
buf = np.asarray(buf, dtype=object)
|
|
61
|
-
items = buf.tolist()
|
|
62
|
-
items.
|
|
73
|
+
items = np.atleast_1d(buf).tolist()
|
|
74
|
+
items.append(buf.dtype.str)
|
|
75
|
+
items.append(buf.shape)
|
|
63
76
|
return self._encoder.encode(items).encode(self._text_encoding)
|
|
64
77
|
|
|
65
78
|
def decode(self, buf, out=None):
|
|
66
79
|
items = self._decoder.decode(ensure_text(buf, self._text_encoding))
|
|
67
80
|
dec = np.empty(items[-1], dtype=items[-2])
|
|
68
|
-
|
|
81
|
+
if not items[-1]:
|
|
82
|
+
dec[...] = items[0]
|
|
83
|
+
else:
|
|
84
|
+
dec[:] = items[:-2]
|
|
69
85
|
if out is not None:
|
|
70
86
|
np.copyto(out, dec)
|
|
71
87
|
return out
|
|
@@ -79,12 +95,13 @@ class JSON(Codec):
|
|
|
79
95
|
return config
|
|
80
96
|
|
|
81
97
|
def __repr__(self):
|
|
82
|
-
params = ['encoding
|
|
98
|
+
params = [f'encoding={self._text_encoding!r}']
|
|
83
99
|
for k, v in sorted(self._encoder_config.items()):
|
|
84
|
-
params.append('{}={!r}'
|
|
100
|
+
params.append(f'{k}={v!r}')
|
|
85
101
|
for k, v in sorted(self._decoder_config.items()):
|
|
86
|
-
params.append('{}={!r}'
|
|
102
|
+
params.append(f'{k}={v!r}')
|
|
87
103
|
classname = type(self).__name__
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
104
|
+
params = ', '.join(params)
|
|
105
|
+
return textwrap.fill(
|
|
106
|
+
f'{classname}({params})', width=80, break_long_words=False, subsequent_indent=' '
|
|
107
|
+
)
|
|
Binary file
|
numcodecs/lzma.py
CHANGED
|
@@ -9,9 +9,8 @@ except ImportError: # pragma: no cover
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
if _lzma:
|
|
12
|
-
|
|
13
12
|
from .abc import Codec
|
|
14
|
-
from .compat import
|
|
13
|
+
from .compat import ensure_contiguous_ndarray, ndarray_copy
|
|
15
14
|
|
|
16
15
|
# noinspection PyShadowingBuiltins
|
|
17
16
|
class LZMA(Codec):
|
|
@@ -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,4 @@ if _lzma:
|
|
|
64
66
|
return ndarray_copy(dec, out)
|
|
65
67
|
|
|
66
68
|
def __repr__(self):
|
|
67
|
-
|
|
68
|
-
(type(self).__name__, self.format, self.check, self.preset,
|
|
69
|
-
self.filters)
|
|
70
|
-
return r
|
|
69
|
+
return f'{type(self).__name__}(format={self.format!r}, check={self.check!r}, preset={self.preset!r}, filters={self.filters!r})'
|