Skip to content

Commit b588f0f

Browse files
authored
Remove deprecated blosc code (#712)
* Remove deprecated blosc code * mypy fixes
1 parent 725cf25 commit b588f0f

File tree

8 files changed

+27
-196
lines changed

8 files changed

+27
-196
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/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')

numcodecs/tests/test_blosc.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
check_backwards_compatibility,
1616
check_config,
1717
check_encode_decode,
18-
check_encode_decode_partial,
1918
check_err_decode_object_buffer,
2019
check_err_encode_object_buffer,
2120
check_max_buffer_size,
@@ -75,19 +74,6 @@ def test_encode_decode(array, codec):
7574
check_encode_decode(array, codec)
7675

7776

78-
@pytest.mark.parametrize('codec', codecs)
79-
@pytest.mark.parametrize(
80-
'array',
81-
[
82-
pytest.param(x) if len(x.shape) == 1 else pytest.param(x, marks=[pytest.mark.xfail])
83-
for x in arrays
84-
],
85-
)
86-
def test_partial_decode(codec, array):
87-
_skip_null(codec)
88-
check_encode_decode_partial(array, codec)
89-
90-
9177
def test_config():
9278
codec = Blosc(cname='zstd', clevel=3, shuffle=1)
9379
check_config(codec)

numcodecs/zarr3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def __init__(self, **codec_config: dict[str, JSON]) -> None:
286286

287287
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
288288
if astype := self.codec_config.get("astype"):
289-
return replace(chunk_spec, dtype=np.dtype(astype)) # type: ignore[arg-type]
289+
return replace(chunk_spec, dtype=np.dtype(astype)) # type: ignore[call-overload]
290290
return chunk_spec
291291

292292

@@ -304,7 +304,7 @@ def __init__(self, **codec_config: JSON) -> None:
304304

305305
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
306306
if astype := self.codec_config.get("astype"):
307-
return replace(chunk_spec, dtype=np.dtype(astype)) # type: ignore[arg-type]
307+
return replace(chunk_spec, dtype=np.dtype(astype)) # type: ignore[call-overload]
308308
return chunk_spec
309309

310310
def evolve_from_array_spec(self, array_spec: ArraySpec) -> FixedScaleOffset:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description = """
1414
A Python package providing buffer compression and transformation codecs \
1515
for use in data storage and communication applications."""
1616
readme = "README.rst"
17-
dependencies = ["numpy>=1.24", "deprecated", "typing_extensions"]
17+
dependencies = ["numpy>=1.24", "typing_extensions"]
1818
requires-python = ">=3.11"
1919
dynamic = [
2020
"version",

0 commit comments

Comments
 (0)