Skip to content

Commit a63982f

Browse files
committed
fix json roundtrip tests
1 parent 65c2415 commit a63982f

File tree

3 files changed

+523
-18
lines changed

3 files changed

+523
-18
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ test = [
8282
"pytest-xdist",
8383
"packaging",
8484
"tomlkit",
85-
"uv"
85+
"uv",
86+
"pcodec",
87+
"zfpy"
8688
]
8789
remote_tests = [
8890
'zarr[remote]',

src/zarr/codecs/numcodecs/_codecs.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import asyncio
2828
import math
2929
from dataclasses import dataclass, replace
30-
from functools import cached_property
3130
from typing import (
3231
TYPE_CHECKING,
3332
Any,
@@ -83,26 +82,26 @@
8382

8483
# Configuration classes for codec parameters
8584
class LZ4Config(TypedDict):
86-
acceleration: NotRequired[int]
85+
acceleration: int
8786

8887

8988
class ZlibConfig(TypedDict):
90-
level: NotRequired[int]
89+
level: int
9190

9291

9392
class BZ2Config(TypedDict):
94-
level: NotRequired[int]
93+
level: int
9594

9695

9796
class LZMAConfig(TypedDict):
98-
format: NotRequired[int]
99-
check: NotRequired[int]
100-
preset: NotRequired[int]
101-
filters: NotRequired[list[dict[str, Any]]]
97+
format: int
98+
check: int
99+
preset: int | None
100+
filters: list[dict[str, Any]] | None
102101

103102

104103
class ShuffleConfig(TypedDict):
105-
elementsize: NotRequired[int]
104+
elementsize: int
106105

107106

108107
class LZ4JSON_V2(LZ4Config):
@@ -158,7 +157,7 @@ class ShuffleJSON_V3(NamedRequiredConfig[Literal["shuffle"], ShuffleConfig]):
158157
# Array-to-array codec configuration classes
159158
class DeltaConfig(TypedDict):
160159
dtype: str
161-
astype: NotRequired[str]
160+
astype: str
162161

163162

164163
class BitRoundConfig(TypedDict):
@@ -183,7 +182,7 @@ class PackBitsConfig(TypedDict):
183182

184183
class AsTypeConfig(TypedDict):
185184
encode_dtype: str
186-
decode_dtype: NotRequired[str]
185+
decode_dtype: str
187186

188187

189188
# Array-to-array codec JSON representations
@@ -364,18 +363,16 @@ def _warn_unstable_specification(obj: _NumcodecsCodec) -> None:
364363
class _NumcodecsCodec:
365364
codec_name: str
366365
_codec_id: ClassVar[str]
366+
_codec: Numcodec
367367
codec_config: Mapping[str, Any]
368368

369369
def __init__(self, **codec_config: Any) -> None:
370-
object.__setattr__(self, "codec_config", codec_config)
370+
object.__setattr__(self, "_codec", get_numcodec({"id": self._codec_id, **codec_config})) # type: ignore[typeddict-item]
371+
object.__setattr__(self, "codec_config", self._codec.get_config())
371372

372373
def to_dict(self) -> dict[str, JSON]:
373374
return cast(dict[str, JSON], self.to_json(zarr_format=3))
374375

375-
@cached_property
376-
def _codec(self) -> Numcodec:
377-
return get_numcodec({"id": self._codec_id, **self.codec_config}) # type: ignore[typeddict-item]
378-
379376
@classmethod
380377
def _from_json_v2(cls, data: CodecJSON_V2) -> Self:
381378
return cls(**data)

0 commit comments

Comments
 (0)