Skip to content

Commit 41fdb1f

Browse files
authored
Merge branch 'main' into ruff_0.9.1
2 parents 93d0c56 + b8e40f7 commit 41fdb1f

File tree

15 files changed

+76
-30
lines changed

15 files changed

+76
-30
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ repos:
1414
- id: debug-statements
1515

1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.9.1
17+
rev: v0.9.4
1818
hooks:
1919
- id: ruff
2020
args: ["--fix", "--show-fixes"]
2121
- id: ruff-format
2222

2323
- repo: https://github.com/scientific-python/cookie
24-
rev: 2024.08.19
24+
rev: 2025.01.22
2525
hooks:
2626
- id: sp-repo-review
2727

2828
- repo: https://github.com/pre-commit/mirrors-mypy
29-
rev: v1.14.0
29+
rev: v1.14.1
3030
hooks:
3131
- id: mypy
3232
args: [--config-file, pyproject.toml]

docs/release.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,27 @@ Release notes
1111
Unreleased
1212
----------
1313

14+
1415
.. _unreleased:
1516

1617
Unreleased
1718
----------
1819

20+
Improvements
21+
~~~~~~~~~~~~
22+
* Raise a custom `UnknownCodecError` when trying to retrieve an unavailable codec.
23+
By :user:`Cas Wognum <cwognum>`.
24+
25+
Fixes
26+
~~~~~
27+
* Remove redundant ``id`` from codec metadata serialization in Zarr3 codecs.
28+
By :user:`Norman Rzepka <normanrz>`, :issue:`685`
29+
30+
.. _release_0.15.0:
31+
32+
0.15.0
33+
------
34+
1935
Breaking changes
2036
~~~~~~~~~~~~~~~~
2137
* All arguments to the ``PCodec`` constructor except for ``level``
@@ -36,11 +52,16 @@ This is because they are not intended to be public API.
3652
In addition, ``numcodecs.blosc.decompress_partial`` is deprecated as
3753
has always been experimental and there is no equivalent in the official
3854
blsoc Python package.
55+
By :user:`David Stansby <dstansby>`, :issue`619`
3956

4057
Fixes
4158
~~~~~
4259
* Fixes issue with ``Delta`` Zarr 3 codec not working with ``astype``.
4360
By :user:`Norman Rzepka <normanrz>`, :issue:`664`
61+
* Cleanup ``PCodec`` soft dependency.
62+
Previously importing ``numcodecs.pcodec`` would work if ``pcodec`` is not installed,
63+
but now it will fail to import. This mirrors the behaviour of other optional dependencies.
64+
By :user:`John Kirkham <jakirkham>`, :issue:`647`
4465
* Fixes issues with the upcoming ``zarr`` 3.0.0 release.
4566
By :user:`Norman Rzepka <normanrz>`, :issue:`675`
4667

@@ -64,6 +85,7 @@ Improvements
6485
are still silently caught.
6586
By :user:`David Stansby <dstansby>`, :issue:`550`.
6687

88+
.. _release_0.14.1:
6789

6890
0.14.1
6991
------

numcodecs/checksum32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
_crc32c: Optional[ModuleType] = None
1515
with suppress(ImportError):
16-
import crc32c as _crc32c # type: ignore[no-redef]
16+
import crc32c as _crc32c # type: ignore[no-redef, unused-ignore]
1717

1818
if TYPE_CHECKING: # pragma: no cover
1919
from typing_extensions import Buffer

numcodecs/delta.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ def encode(self, buf):
6363
enc[0] = arr[0]
6464

6565
# compute differences
66-
# using np.subtract for in-place operations
67-
if arr.dtype == bool:
68-
np.not_equal(arr[1:], arr[:-1], out=enc[1:])
69-
else:
70-
np.subtract(arr[1:], arr[:-1], out=enc[1:])
71-
66+
enc[1:] = np.diff(arr)
7267
return enc
7368

7469
def decode(self, buf, out=None):

numcodecs/errors.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
This module defines custom exceptions that are raised in the `numcodecs` codebase.
3+
"""
4+
5+
6+
class UnknownCodecError(ValueError):
7+
"""
8+
An exception that is raised when trying to receive a codec that has not been registered.
9+
10+
Parameters
11+
----------
12+
codec_id : str
13+
Codec identifier.
14+
15+
Examples
16+
----------
17+
>>> import numcodecs
18+
>>> numcodecs.get_codec({"codec_id": "unknown"})
19+
Traceback (most recent call last):
20+
...
21+
UnknownCodecError: codec not available: 'unknown'
22+
"""
23+
24+
def __init__(self, codec_id: str):
25+
self.codec_id = codec_id
26+
super().__init__(f"codec not available: '{codec_id}'")

numcodecs/json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
def encode(self, buf):
6969
try:
7070
buf = np.asarray(buf)
71-
except ValueError:
71+
except ValueError: # pragma: no cover
7272
buf = np.asarray(buf, dtype=object)
7373
items = np.atleast_1d(buf).tolist()
7474
items.append(buf.dtype.str)

numcodecs/pcodec.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
from numcodecs.abc import Codec
44
from numcodecs.compat import ensure_contiguous_ndarray
5-
6-
try:
7-
from pcodec import ChunkConfig, DeltaSpec, ModeSpec, PagingSpec, standalone
8-
except ImportError: # pragma: no cover
9-
standalone = None
10-
5+
from pcodec import ChunkConfig, DeltaSpec, ModeSpec, PagingSpec, standalone
116

127
DEFAULT_MAX_PAGE_N = 262144
138

@@ -58,9 +53,6 @@ def __init__(
5853
delta_encoding_order: int | None = None,
5954
equal_pages_up_to: int = DEFAULT_MAX_PAGE_N,
6055
):
61-
if standalone is None: # pragma: no cover
62-
raise ImportError("pcodec must be installed to use the PCodec codec.")
63-
6456
# note that we use `level` instead of `compression_level` to
6557
# match other codecs
6658
self.level = level

numcodecs/quantize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def encode(self, buf):
6565
precision = 10.0**-self.digits
6666
exp = math.log10(precision)
6767
if exp < 0:
68-
exp = int(math.floor(exp))
68+
exp = math.floor(exp)
6969
else:
70-
exp = int(math.ceil(exp))
70+
exp = math.ceil(exp)
7171
bits = math.ceil(math.log2(10.0**-exp))
7272
scale = 2.0**bits
7373
enc = np.around(scale * arr) / scale

numcodecs/registry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from importlib.metadata import EntryPoints, entry_points
66

77
from numcodecs.abc import Codec
8+
from numcodecs.errors import UnknownCodecError
89

910
logger = logging.getLogger("numcodecs")
1011
codec_registry: dict[str, Codec] = {}
@@ -50,7 +51,7 @@ def get_codec(config):
5051
register_codec(cls, codec_id=codec_id)
5152
if cls:
5253
return cls.from_config(config)
53-
raise ValueError(f'codec not available: {codec_id!r}')
54+
raise UnknownCodecError(f"{codec_id!r}")
5455

5556

5657
def register_codec(cls, codec_id=None):

numcodecs/tests/test_pcodec.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import numpy as np
22
import pytest
33

4-
from numcodecs.pcodec import PCodec
5-
64
try:
7-
# initializing codec triggers ImportError
8-
PCodec()
5+
from numcodecs.pcodec import PCodec
96
except ImportError: # pragma: no cover
107
pytest.skip("pcodec not available", allow_module_level=True)
118

0 commit comments

Comments
 (0)