Skip to content

Commit b770694

Browse files
committed
Merge branch 'main' of github.com:zarr-developers/zarr-python into feat/v2-v3-codecs
2 parents bc43d5a + 48e7f4d commit b770694

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

changes/3483.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug that prevented `PCodec` from being properly resolved when loading arrays using that compressor.

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ test = [
8585
"packaging",
8686
"tomlkit",
8787
"uv",
88-
"pcodec",
89-
"zfpy"
9088
]
9189
remote_tests = [
9290
'zarr[remote]',

src/zarr/codecs/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@
9797
)
9898
register_codec("jenkins_lookup3", JenkinsLookup3, qualname="zarr.codecs.numcodecs.JenkinsLookup3")
9999
register_codec("numcodecs.pcodec", PCodec, qualname="zarr.codecs.numcodecs.pcodec")
100-
register_codec("pcodec", PCodec, qualname="zarr.codecs.numcodecs.pcodec")
100+
register_codec("pcodec", PCodec, qualname="zarr.codecs.numcodecs.PCodec")
101+
register_codec("numcodecs.pcodec", PCodec, qualname="zarr.codecs.numcodecs.PCodec")
101102
register_codec("numcodecs.packbits", PackBits, qualname="zarr.codecs.numcodecs.PackBits")
102103
register_codec("packbits", PackBits, qualname="zarr.codecs.numcodecs.PackBits")
103104
register_codec("numcodecs.quantize", Quantize, qualname="zarr.codecs.numcodecs.Quantize")

src/zarr/codecs/sharding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ def validate(
570570
)
571571
):
572572
raise ValueError(
573-
"The array's `chunk_shape` needs to be divisible by the shard's inner `chunk_shape`."
573+
f"The array's `chunk_shape` (got {chunk_grid.chunk_shape}) "
574+
f"needs to be divisible by the shard's inner `chunk_shape` (got {self.chunk_shape})."
574575
)
575576

576577
async def _decode_single(

tests/test_codecs/test_numcodecs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from zarr.codecs import numcodecs as _numcodecs
1414
from zarr.codecs._v2 import codec_json_v2_to_v3
1515
from zarr.errors import ZarrUserWarning
16-
from zarr.registry import get_numcodec
16+
from zarr.registry import get_codec_class, get_numcodec
1717

1818
if TYPE_CHECKING:
1919
from collections.abc import Iterator
@@ -81,18 +81,23 @@ def test_is_numcodec_cls() -> None:
8181

8282
ALL_CODECS = tuple(
8383
filter(
84-
lambda v: isinstance(v, _numcodecs._NumcodecsCodec),
84+
lambda v: issubclass(v, _numcodecs._NumcodecsCodec) and hasattr(v, "codec_name"),
8585
tuple(getattr(_numcodecs, cls_name) for cls_name in _numcodecs.__all__),
8686
)
8787
)
8888

8989

90+
@pytest.mark.parametrize("codec_cls", ALL_CODECS)
91+
def test_get_codec_class(codec_cls: type[_numcodecs._NumcodecsCodec]) -> None:
92+
assert get_codec_class(codec_cls.codec_name) == codec_cls # type: ignore[comparison-overlap]
93+
94+
9095
@pytest.mark.parametrize("codec_class", ALL_CODECS)
9196
def test_docstring(codec_class: type[_numcodecs._NumcodecsCodec]) -> None:
9297
"""
9398
Test that the docstring for the zarr.numcodecs codecs references the wrapped numcodecs class.
9499
"""
95-
assert "See :class:`numcodecs." in codec_class.__doc__ # type: ignore[operator]
100+
assert "See [numcodecs." in codec_class.__doc__ # type: ignore[operator]
96101

97102

98103
@pytest.mark.parametrize(

tests/test_codecs/test_sharding.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pickle
2+
import re
23
from typing import TYPE_CHECKING, Any, Literal
34

45
import numpy as np
@@ -528,3 +529,20 @@ def test_invalid_metadata(store: Store) -> None:
528529
dtype=np.dtype("uint8"),
529530
fill_value=0,
530531
)
532+
533+
534+
def test_invalid_shard_shape() -> None:
535+
with pytest.raises(
536+
ValueError,
537+
match=re.escape(
538+
"The array's `chunk_shape` (got (16, 16)) needs to be divisible by the shard's inner `chunk_shape` (got (9,))."
539+
),
540+
):
541+
zarr.create_array(
542+
{},
543+
shape=(16, 16),
544+
shards=(16, 16),
545+
chunks=(9,),
546+
dtype=np.dtype("uint8"),
547+
fill_value=0,
548+
)

0 commit comments

Comments
 (0)