Skip to content

Commit 42df7bc

Browse files
authored
Merge branch 'main' into dependabot/github_actions/pypa/cibuildwheel-2.23.2
2 parents 7218629 + b588f0f commit 42df7bc

File tree

9 files changed

+50
-209
lines changed

9 files changed

+50
-209
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ repos:
3030
hooks:
3131
- id: mypy
3232
args: [--config-file, pyproject.toml]
33-
additional_dependencies: [numpy, pytest, crc32c, zfpy, 'zarr>=3.0.0rc1']
33+
additional_dependencies: [numpy, pytest, crc32c, zfpy, 'zarr>=3']

docs/release.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,30 @@ Unreleased
2020
Enhancements
2121
~~~~~~~~~~~~
2222

23-
* Add support for the Linux AArch64 architecture, and bump the minimum
23+
* Add support for the Linux aarch64 architecture, and bump the minimum
2424
macOS deployment target for x86_64 to 10.13.
2525
By :user:`Agriya Khetarpal <agriyakhetarpal>`, :issue:`288`.
2626

27+
Removals
28+
~~~~~~~~
29+
30+
The following ``blosc`` funcitons are removed, with no replacement.
31+
This is because they were not intended to be public API.
32+
33+
- ``numcodecs.blosc.init``
34+
- ``numcodecs.blosc.destroy``
35+
- ``numcodecs.blosc.compname_to_compcode``
36+
- ``numcodecs.blosc.cbuffer_sizes``
37+
- ``numcodecs.blosc.cbuffer_metainfo``
38+
39+
In addition, ``numcodecs.blosc.decompress_partial`` is removed as
40+
has always been experimental and there is no equivalent in the official
41+
blsoc Python package.
42+
By :user:`David Stansby <dstansby>`, :issue:`712`
43+
44+
0.15.1
45+
------
46+
2747
Improvements
2848
~~~~~~~~~~~~
2949
* Raise a custom `UnknownCodecError` when trying to retrieve an unavailable codec.
@@ -70,7 +90,7 @@ This is because they are not intended to be public API.
7090
In addition, ``numcodecs.blosc.decompress_partial`` is deprecated as
7191
has always been experimental and there is no equivalent in the official
7292
blsoc Python package.
73-
By :user:`David Stansby <dstansby>`, :issue`619`
93+
By :user:`David Stansby <dstansby>`, :issue:`619`
7494

7595
Fixes
7696
~~~~~

numcodecs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
ncores = 1
5252
blosc._init()
5353
blosc.set_nthreads(min(8, ncores))
54-
atexit.register(blosc.destroy)
54+
atexit.register(blosc._destroy)
5555

5656
from numcodecs import zstd as zstd
5757
from numcodecs.zstd import Zstd

numcodecs/blosc.pyx

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import threading
77
import multiprocessing
88
import os
9-
from deprecated import deprecated
109

1110

1211
from cpython.bytes cimport PyBytes_AS_STRING, PyBytes_FromStringAndSize
@@ -44,7 +43,6 @@ cdef extern from "blosc.h":
4443
void* src, void* dest, size_t destsize) nogil
4544
int blosc_decompress(void *src, void *dest, size_t destsize) nogil
4645
int blosc_getitem(void* src, int start, int nitems, void* dest)
47-
int blosc_compname_to_compcode(const char* compname)
4846
int blosc_compress_ctx(int clevel, int doshuffle, size_t typesize, size_t nbytes,
4947
const void* src, void* dest, size_t destsize,
5048
const char* compressor, size_t blocksize,
@@ -99,28 +97,12 @@ def _init():
9997
"""Initialize the Blosc library environment."""
10098
blosc_init()
10199

102-
init = deprecated(_init)
103-
104100

105101
def _destroy():
106102
"""Destroy the Blosc library environment."""
107103
blosc_destroy()
108104

109105

110-
destroy = deprecated(_destroy)
111-
112-
113-
def _compname_to_compcode(cname):
114-
"""Return the compressor code associated with the compressor name. If the compressor
115-
name is not recognized, or there is not support for it in this build, -1 is returned
116-
instead."""
117-
if isinstance(cname, str):
118-
cname = cname.encode('ascii')
119-
return blosc_compname_to_compcode(cname)
120-
121-
compname_to_compcode = deprecated(_compname_to_compcode)
122-
123-
124106
def list_compressors():
125107
"""Get a list of compressors supported in the current build."""
126108
s = blosc_list_compressors()
@@ -166,7 +148,6 @@ def _cbuffer_sizes(source):
166148

167149
return nbytes, cbytes, blocksize
168150

169-
cbuffer_sizes = deprecated(_cbuffer_sizes)
170151

171152
def cbuffer_complib(source):
172153
"""Return the name of the compression library used to compress `source`."""
@@ -222,13 +203,10 @@ def _cbuffer_metainfo(source):
222203

223204
return typesize, shuffle, memcpyed
224205

225-
cbuffer_metainfo = deprecated(_cbuffer_metainfo)
226-
227206
def _err_bad_cname(cname):
228207
raise ValueError('bad compressor or compressor not supported: %r; expected one of '
229208
'%s' % (cname, list_compressors()))
230209

231-
err_bad_cname = deprecated(_err_bad_cname)
232210

233211
def compress(source, char* cname, int clevel, int shuffle=SHUFFLE,
234212
int blocksize=AUTOBLOCKS, typesize=None):
@@ -423,86 +401,6 @@ def decompress(source, dest=None):
423401
return dest
424402

425403

426-
def _decompress_partial(source, start, nitems, dest=None):
427-
"""**Experimental**
428-
Decompress data of only a part of a buffer.
429-
430-
Parameters
431-
----------
432-
source : bytes-like
433-
Compressed data, including blosc header. Can be any object supporting the buffer
434-
protocol.
435-
start: int,
436-
Offset in item where we want to start decoding
437-
nitems: int
438-
Number of items we want to decode
439-
dest : array-like, optional
440-
Object to decompress into.
441-
442-
443-
Returns
444-
-------
445-
dest : bytes
446-
Object containing decompressed data.
447-
448-
"""
449-
cdef:
450-
int ret
451-
int encoding_size
452-
int nitems_bytes
453-
int start_bytes
454-
memoryview source_mv
455-
const Py_buffer* source_pb
456-
const char* source_ptr
457-
memoryview dest_mv
458-
Py_buffer* dest_pb
459-
char* dest_ptr
460-
size_t dest_nbytes
461-
462-
# obtain source memoryview
463-
source_mv = ensure_continguous_memoryview(source)
464-
source_pb = PyMemoryView_GET_BUFFER(source_mv)
465-
466-
# setup source pointer
467-
source_ptr = <const char*>source_pb.buf
468-
469-
# get encoding size from source buffer header
470-
encoding_size = source[3]
471-
472-
# convert variables to handle type and encoding sizes
473-
nitems_bytes = nitems * encoding_size
474-
start_bytes = (start * encoding_size)
475-
476-
# setup destination buffer
477-
if dest is None:
478-
# allocate memory
479-
dest_1d = dest = PyBytes_FromStringAndSize(NULL, nitems_bytes)
480-
else:
481-
dest_1d = ensure_contiguous_ndarray(dest)
482-
483-
# obtain dest memoryview
484-
dest_mv = memoryview(dest_1d)
485-
dest_pb = PyMemoryView_GET_BUFFER(dest_mv)
486-
dest_ptr = <char*>dest_pb.buf
487-
dest_nbytes = dest_pb.len
488-
489-
# try decompression
490-
try:
491-
if dest_nbytes < nitems_bytes:
492-
raise ValueError('destination buffer too small; expected at least %s, '
493-
'got %s' % (nitems_bytes, dest_nbytes))
494-
ret = blosc_getitem(source_ptr, start, nitems, dest_ptr)
495-
finally:
496-
pass
497-
498-
# ret refers to the number of bytes returned from blosc_getitem.
499-
if ret <= 0:
500-
raise RuntimeError('error during blosc partial decompression: %d', ret)
501-
502-
return dest
503-
504-
decompress_partial = deprecated(_decompress_partial)
505-
506404
# set the value of this variable to True or False to override the
507405
# default adaptive behaviour
508406
use_threads = None
@@ -601,11 +499,6 @@ class Blosc(Codec):
601499
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
602500
return decompress(buf, out)
603501

604-
def decode_partial(self, buf, int start, int nitems, out=None):
605-
'''**Experimental**'''
606-
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
607-
return _decompress_partial(buf, start, nitems, dest=out)
608-
609502
def __repr__(self):
610503
r = '%s(cname=%r, clevel=%r, shuffle=%s, blocksize=%s)' % \
611504
(type(self).__name__,

numcodecs/checksum32.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import abc
12
import struct
23
import zlib
3-
from collections.abc import Callable
44
from contextlib import suppress
55
from types import ModuleType
6-
from typing import TYPE_CHECKING, Literal, Optional
6+
from typing import Literal, Optional
77

88
import numpy as np
9+
from typing_extensions import Buffer
910

1011
from .abc import Codec
1112
from .compat import ensure_contiguous_ndarray, ndarray_copy
@@ -15,15 +16,11 @@
1516
with suppress(ImportError):
1617
import crc32c as _crc32c # type: ignore[no-redef, unused-ignore]
1718

18-
if TYPE_CHECKING: # pragma: no cover
19-
from typing_extensions import Buffer
20-
2119
CHECKSUM_LOCATION = Literal['start', 'end']
2220

2321

24-
class Checksum32(Codec):
22+
class Checksum32(Codec, abc.ABC):
2523
# override in sub-class
26-
checksum: Callable[["Buffer", int], int] | None = None
2724
location: CHECKSUM_LOCATION = 'start'
2825

2926
def __init__(self, location: CHECKSUM_LOCATION | None = None):
@@ -67,6 +64,10 @@ def decode(self, buf, out=None):
6764
)
6865
return ndarray_copy(payload_view, out)
6966

67+
@staticmethod
68+
@abc.abstractmethod
69+
def checksum(data: Buffer, value: int) -> int: ...
70+
7071

7172
class CRC32(Checksum32):
7273
"""Codec add a crc32 checksum to the buffer.
@@ -78,9 +79,15 @@ class CRC32(Checksum32):
7879
"""
7980

8081
codec_id = 'crc32'
81-
checksum = zlib.crc32
8282
location = 'start'
8383

84+
@staticmethod
85+
def checksum(data: Buffer, value: int = 0) -> int:
86+
"""
87+
Thin wrapper around ``zlib.crc32``.
88+
"""
89+
return zlib.crc32(data, value)
90+
8491

8592
class Adler32(Checksum32):
8693
"""Codec add a adler32 checksum to the buffer.
@@ -92,9 +99,15 @@ class Adler32(Checksum32):
9299
"""
93100

94101
codec_id = 'adler32'
95-
checksum = zlib.adler32
96102
location = 'start'
97103

104+
@staticmethod
105+
def checksum(data: Buffer, value: int = 1) -> int:
106+
"""
107+
Thin wrapper around ``zlib.adler32``.
108+
"""
109+
return zlib.adler32(data, value)
110+
98111

99112
class JenkinsLookup3(Checksum32):
100113
"""Bob Jenkin's lookup3 checksum with 32-bit output

numcodecs/tests/common.py

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -115,74 +115,6 @@ def check_encode_decode(arr, codec, precision=None):
115115
compare_arrays(arr, out, precision=precision)
116116

117117

118-
def check_encode_decode_partial(arr, codec, precision=None):
119-
# N.B., watch out here with blosc compressor, if the itemsize of
120-
# the source buffer is different then the results of encoding
121-
# (i.e., compression) may be different. Hence we *do not* require that
122-
# the results of encoding be identical for all possible inputs, rather
123-
# we just require that the results of the encode/decode round-trip can
124-
# be compared to the original array.
125-
126-
itemsize = arr.itemsize
127-
start, nitems = 5, 10
128-
compare_arr = arr[start : start + nitems]
129-
# test encoding of numpy array
130-
enc = codec.encode(arr)
131-
dec = codec.decode_partial(enc, start, nitems)
132-
compare_arrays(compare_arr, dec, precision=precision)
133-
134-
# out = np.empty_like(compare_arr)
135-
out = np.empty_like(compare_arr)
136-
print(len(out))
137-
138-
# test partial decode of encoded bytes
139-
buf = arr.tobytes(order='A')
140-
enc = codec.encode(buf)
141-
dec = codec.decode_partial(enc, start * itemsize, nitems * itemsize, out=out)
142-
compare_arrays(compare_arr, dec, precision=precision)
143-
144-
# test partial decode of encoded bytearray
145-
buf = bytearray(arr.tobytes(order='A'))
146-
enc = codec.encode(buf)
147-
dec = codec.decode_partial(enc, start * itemsize, nitems * itemsize, out=out)
148-
compare_arrays(compare_arr, dec, precision=precision)
149-
150-
# test partial decode of encoded array.array
151-
buf = array.array('b', arr.tobytes(order='A'))
152-
enc = codec.encode(buf)
153-
dec = codec.decode_partial(enc, start * itemsize, nitems * itemsize, out=out)
154-
compare_arrays(compare_arr, dec, precision=precision)
155-
156-
# # decoding should support any object exporting the buffer protocol,
157-
158-
# # setup
159-
enc_bytes = ensure_bytes(enc)
160-
161-
# test decoding of raw bytes into numpy array
162-
dec = codec.decode_partial(enc_bytes, start * itemsize, nitems * itemsize, out=out)
163-
compare_arrays(compare_arr, dec, precision=precision)
164-
165-
# test partial decoding of bytearray
166-
dec = codec.decode_partial(bytearray(enc_bytes), start * itemsize, nitems * itemsize, out=out)
167-
compare_arrays(compare_arr, dec, precision=precision)
168-
169-
# test partial decoding of array.array
170-
buf = array.array('b', enc_bytes)
171-
dec = codec.decode_partial(buf, start * itemsize, nitems * itemsize, out=out)
172-
compare_arrays(compare_arr, dec, precision=precision)
173-
174-
# test decoding of numpy array into numpy array
175-
buf = np.frombuffer(enc_bytes, dtype='u1')
176-
dec = codec.decode_partial(buf, start * itemsize, nitems * itemsize, out=out)
177-
compare_arrays(compare_arr, dec, precision=precision)
178-
179-
# test decoding directly into bytearray
180-
out = bytearray(compare_arr.nbytes)
181-
codec.decode_partial(enc_bytes, start * itemsize, nitems * itemsize, out=out)
182-
# noinspection PyTypeChecker
183-
compare_arrays(compare_arr, out, precision=precision)
184-
185-
186118
def assert_array_items_equal(res, arr):
187119
assert isinstance(res, np.ndarray)
188120
res = res.reshape(-1, order='A')

0 commit comments

Comments
 (0)