Skip to content

Commit 810364c

Browse files
committed
Remove deprecated blosc code
1 parent a2bdbe5 commit 810364c

File tree

6 files changed

+24
-220
lines changed

6 files changed

+24
-220
lines changed

docs/release.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ Release notes
1717
Unreleased
1818
----------
1919

20+
Removals
21+
~~~~~~~~
22+
23+
The following ``blosc`` funcitons are removed, with no replacement.
24+
This is because they were not intended to be public API.
25+
26+
- ``numcodecs.blosc.init``
27+
- ``numcodecs.blosc.destroy``
28+
- ``numcodecs.blosc.compname_to_compcode``
29+
- ``numcodecs.blosc.cbuffer_sizes``
30+
- ``numcodecs.blosc.cbuffer_metainfo``
31+
32+
In addition, ``numcodecs.blosc.decompress_partial`` is removed as
33+
has always been experimental and there is no equivalent in the official
34+
blsoc Python package.
35+
By :user:`David Stansby <dstansby>`, :issue:`712`
36+
37+
0.15.1
38+
------
39+
2040
Improvements
2141
~~~~~~~~~~~~
2242
* Raise a custom `UnknownCodecError` when trying to retrieve an unavailable codec.
@@ -52,7 +72,7 @@ This is because they are not intended to be public API.
5272
In addition, ``numcodecs.blosc.decompress_partial`` is deprecated as
5373
has always been experimental and there is no equivalent in the official
5474
blsoc Python package.
55-
By :user:`David Stansby <dstansby>`, :issue`619`
75+
By :user:`David Stansby <dstansby>`, :issue:`619`
5676

5777
Fixes
5878
~~~~~

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 & 131 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.buffer cimport PyBUF_ANY_CONTIGUOUS, PyBUF_WRITEABLE
@@ -45,7 +44,6 @@ cdef extern from "blosc.h":
4544
void* src, void* dest, size_t destsize) nogil
4645
int blosc_decompress(void *src, void *dest, size_t destsize) nogil
4746
int blosc_getitem(void* src, int start, int nitems, void* dest)
48-
int blosc_compname_to_compcode(const char* compname)
4947
int blosc_compress_ctx(int clevel, int doshuffle, size_t typesize, size_t nbytes,
5048
const void* src, void* dest, size_t destsize,
5149
const char* compressor, size_t blocksize,
@@ -100,28 +98,12 @@ def _init():
10098
"""Initialize the Blosc library environment."""
10199
blosc_init()
102100

103-
init = deprecated(_init)
104-
105101

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

110106

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

143125

144-
def _cbuffer_sizes(source):
145-
"""Return information about a compressed buffer, namely the number of uncompressed
146-
bytes (`nbytes`) and compressed (`cbytes`). It also returns the `blocksize` (which
147-
is used internally for doing the compression by blocks).
148-
149-
Returns
150-
-------
151-
nbytes : int
152-
cbytes : int
153-
blocksize : int
154-
155-
"""
156-
cdef:
157-
Buffer buffer
158-
size_t nbytes, cbytes, blocksize
159-
160-
# obtain buffer
161-
buffer = Buffer(source, PyBUF_ANY_CONTIGUOUS)
162-
163-
# determine buffer size
164-
blosc_cbuffer_sizes(buffer.ptr, &nbytes, &cbytes, &blocksize)
165-
166-
# release buffers
167-
buffer.release()
168-
169-
return nbytes, cbytes, blocksize
170-
171-
cbuffer_sizes = deprecated(_cbuffer_sizes)
172-
173126
def cbuffer_complib(source):
174127
"""Return the name of the compression library used to compress `source`."""
175128
cdef:
@@ -226,13 +179,10 @@ def _cbuffer_metainfo(source):
226179

227180
return typesize, shuffle, memcpyed
228181

229-
cbuffer_metainfo = deprecated(_cbuffer_metainfo)
230-
231182
def _err_bad_cname(cname):
232183
raise ValueError('bad compressor or compressor not supported: %r; expected one of '
233184
'%s' % (cname, list_compressors()))
234185

235-
err_bad_cname = deprecated(_err_bad_cname)
236186

237187
def compress(source, char* cname, int clevel, int shuffle=SHUFFLE,
238188
int blocksize=AUTOBLOCKS):
@@ -415,82 +365,6 @@ def decompress(source, dest=None):
415365

416366
return dest
417367

418-
419-
def _decompress_partial(source, start, nitems, dest=None):
420-
"""**Experimental**
421-
Decompress data of only a part of a buffer.
422-
423-
Parameters
424-
----------
425-
source : bytes-like
426-
Compressed data, including blosc header. Can be any object supporting the buffer
427-
protocol.
428-
start: int,
429-
Offset in item where we want to start decoding
430-
nitems: int
431-
Number of items we want to decode
432-
dest : array-like, optional
433-
Object to decompress into.
434-
435-
436-
Returns
437-
-------
438-
dest : bytes
439-
Object containing decompressed data.
440-
441-
"""
442-
cdef:
443-
int ret
444-
int encoding_size
445-
int nitems_bytes
446-
int start_bytes
447-
char *source_ptr
448-
char *dest_ptr
449-
Buffer source_buffer
450-
Buffer dest_buffer = None
451-
452-
# setup source buffer
453-
source_buffer = Buffer(source, PyBUF_ANY_CONTIGUOUS)
454-
source_ptr = source_buffer.ptr
455-
456-
# get encoding size from source buffer header
457-
encoding_size = source[3]
458-
459-
# convert variables to handle type and encoding sizes
460-
nitems_bytes = nitems * encoding_size
461-
start_bytes = (start * encoding_size)
462-
463-
# setup destination buffer
464-
if dest is None:
465-
dest = PyBytes_FromStringAndSize(NULL, nitems_bytes)
466-
dest_ptr = PyBytes_AS_STRING(dest)
467-
dest_nbytes = nitems_bytes
468-
else:
469-
arr = ensure_contiguous_ndarray(dest)
470-
dest_buffer = Buffer(arr, PyBUF_ANY_CONTIGUOUS | PyBUF_WRITEABLE)
471-
dest_ptr = dest_buffer.ptr
472-
dest_nbytes = dest_buffer.nbytes
473-
474-
# try decompression
475-
try:
476-
if dest_nbytes < nitems_bytes:
477-
raise ValueError('destination buffer too small; expected at least %s, '
478-
'got %s' % (nitems_bytes, dest_nbytes))
479-
ret = blosc_getitem(source_ptr, start, nitems, dest_ptr)
480-
481-
finally:
482-
source_buffer.release()
483-
if dest_buffer is not None:
484-
dest_buffer.release()
485-
486-
# ret refers to the number of bytes returned from blosc_getitem.
487-
if ret <= 0:
488-
raise RuntimeError('error during blosc partial decompression: %d', ret)
489-
490-
return dest
491-
492-
decompress_partial = deprecated(_decompress_partial)
493-
494368
# set the value of this variable to True or False to override the
495369
# default adaptive behaviour
496370
use_threads = None
@@ -584,11 +458,6 @@ class Blosc(Codec):
584458
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
585459
return decompress(buf, out)
586460

587-
def decode_partial(self, buf, int start, int nitems, out=None):
588-
'''**Experimental**'''
589-
buf = ensure_contiguous_ndarray(buf, self.max_buffer_size)
590-
return _decompress_partial(buf, start, nitems, dest=out)
591-
592461
def __repr__(self):
593462
r = '%s(cname=%r, clevel=%r, shuffle=%s, blocksize=%s)' % \
594463
(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)

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ name = "numcodecs"
1313
description = """
1414
A Python package providing buffer compression and transformation codecs \
1515
for use in data storage and communication applications."""
16-
readme = "README.rst"
17-
dependencies = [
18-
"numpy>=1.24",
19-
"deprecated"
20-
]
16+
readme = "README.rst"
17+
dependencies = ["numpy>=1.24"]
2118
requires-python = ">=3.11"
2219
dynamic = [
2320
"version",

0 commit comments

Comments
 (0)