Skip to content

Numcodecs in v3 #3037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
typing
  • Loading branch information
brokkoli71 committed May 6, 2025
commit 3811026bd7bcd5dc036a4497833c0396114e57b2
22 changes: 12 additions & 10 deletions src/zarr/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings
from collections import defaultdict
from importlib.metadata import entry_points as get_entry_points
from typing import TYPE_CHECKING, Any, Generic, TypeVar
from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast

import numcodecs

Expand Down Expand Up @@ -179,10 +179,12 @@ def numcodec_to_zarr3_codec(codec: numcodecs.abc.Codec) -> Codec:

numcodecs_zarr3_codec_class = getattr(numcodecs_zarr3_module, codec_name)

config = codec.get_config()
config.pop("id", None)
codec_config = codec.get_config()
codec_config.pop("id", None)

return numcodecs_zarr3_codec_class(**config)
codec = numcodecs_zarr3_codec_class(**codec_config)
codec = cast(Codec, codec)
return codec


def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec:
Expand All @@ -201,9 +203,9 @@ def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec:
msg = f"Expected a dict representation of a BytesBytesCodec; got a dict representation of a {type(result)} instead."
raise TypeError(msg)
else:
if not isinstance(data, BytesBytesCodec):
raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.")
result = data
if not isinstance(result, BytesBytesCodec):
raise TypeError(f"Expected a BytesBytesCodec. Got {type(result)} instead.")
return result


Expand All @@ -223,9 +225,9 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec:
msg = f"Expected a dict representation of a ArrayBytesCodec; got a dict representation of a {type(result)} instead."
raise TypeError(msg)
else:
if not isinstance(data, ArrayBytesCodec):
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
result = data
if not isinstance(result, ArrayBytesCodec):
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(result)} instead.")
return result


Expand All @@ -245,9 +247,9 @@ def _parse_array_array_codec(data: dict[str, JSON] | Codec) -> ArrayArrayCodec:
msg = f"Expected a dict representation of a ArrayArrayCodec; got a dict representation of a {type(result)} instead."
raise TypeError(msg)
else:
if not isinstance(data, ArrayArrayCodec):
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.")
result = data
if not isinstance(result, ArrayArrayCodec):
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(result)} instead.")
return result


Expand Down
4 changes: 2 additions & 2 deletions tests/test_codecs/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ async def test_resize(store: Store) -> None:
(numcodecs.CRC32C(), numcodecs.zarr3.CRC32C),
(numcodecs.LZ4(), numcodecs.zarr3.LZ4),
(numcodecs.LZMA(), numcodecs.zarr3.LZMA),
# (numcodecs.ZFPY(), numcodecs.zarr3.ZFPY),
(numcodecs.ZFPY(), numcodecs.zarr3.ZFPY),
(numcodecs.Adler32(), numcodecs.zarr3.Adler32),
(
numcodecs.AsType(encode_dtype=np.float64, decode_dtype=np.float32),
Expand All @@ -437,7 +437,7 @@ async def test_resize(store: Store) -> None:
(numcodecs.Fletcher32(), numcodecs.zarr3.Fletcher32),
(numcodecs.GZip(), numcodecs.zarr3.GZip),
(numcodecs.JenkinsLookup3(), numcodecs.zarr3.JenkinsLookup3),
# (numcodecs.PCodec(), numcodecs.zarr3.PCodec),
(numcodecs.PCodec(), numcodecs.zarr3.PCodec),
(numcodecs.PackBits(), numcodecs.zarr3.PackBits),
(numcodecs.Quantize(digits=1, dtype="f8"), numcodecs.zarr3.Quantize),
(numcodecs.Shuffle(), numcodecs.zarr3.Shuffle),
Expand Down
Loading