Skip to content

Commit bb76132

Browse files
committed
update typeddicts, and handle location in crc32c codec json
1 parent 9722e9b commit bb76132

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/zarr/codecs/crc32c_.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,27 @@
2020
from zarr.core.buffer import Buffer
2121

2222

23-
class Crc32cConfig(TypedDict): ...
23+
class Crc32cConfig_V2(TypedDict):
24+
location: ReadOnly[Literal["start", "end"]]
2425

2526

26-
class Crc32cJSON_V2(TypedDict):
27+
class Crc32cConfig_V3(TypedDict): ...
28+
29+
30+
class Crc32cJSON_V2(Crc32cConfig_V2):
2731
id: ReadOnly[Literal["crc32c"]]
2832

2933

30-
class Crc32cJSON_V3(NamedConfig[Literal["crc32c"], Crc32cConfig]): ...
34+
class Crc32cJSON_V3(NamedConfig[Literal["crc32c"], Crc32cConfig_V3]): ...
3135

3236

3337
def check_json_v2(data: object) -> TypeGuard[Crc32cJSON_V2]:
34-
return isinstance(data, Mapping) and set(data.keys()) == {"id"} and data["id"] == "crc32c"
38+
return (
39+
isinstance(data, Mapping)
40+
and set(data.keys()) == {"id", "location"}
41+
and data["id"] == "crc32c"
42+
and data["location"] in ("start", "end")
43+
)
3544

3645

3746
def check_json_v3(data: object) -> TypeGuard[Crc32cJSON_V3]:
@@ -55,6 +64,8 @@ def from_dict(cls, data: dict[str, JSON]) -> Self:
5564
@classmethod
5665
def _from_json_v2(cls, data: CodecJSON) -> Self:
5766
if check_json_v2(data):
67+
if data["location"] != "end":
68+
raise ValueError('The crc32c codec only supports the "end" location')
5869
return cls()
5970
msg = (
6071
"Invalid Zarr V2 JSON representation of the crc32c codec. "

src/zarr/codecs/numcodecs/_codecs.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272
from zarr.abc.numcodec import Numcodec
7373
from zarr.codecs.blosc import BloscJSON_V2, BloscJSON_V3
74-
from zarr.codecs.crc32c_ import Crc32cConfig, Crc32cJSON_V2, Crc32cJSON_V3
74+
from zarr.codecs.crc32c_ import Crc32cConfig_V2, Crc32cJSON_V2, Crc32cJSON_V3
7575
from zarr.codecs.gzip import GZipConfig, GZipJSON_V2, GZipJSON_V3
7676
from zarr.codecs.zstd import ZstdConfig_V3, ZstdJSON_V2, ZstdJSON_V3
7777
from zarr.core.array_spec import ArraySpec
@@ -253,6 +253,8 @@ class AsTypeJSON_V3(NamedRequiredConfig[Literal["astype"], AsTypeConfig]):
253253
class Crc32Config(TypedDict):
254254
"""Configuration parameters for CRC32 codec."""
255255

256+
location: Literal["start", "end"]
257+
256258

257259
class Crc32JSON_V2(Crc32Config):
258260
"""JSON representation of CRC32 codec for Zarr V2."""
@@ -267,6 +269,8 @@ class Crc32JSON_V3(NamedConfig[Literal["crc32"], Crc32Config]):
267269
class Adler32Config(TypedDict):
268270
"""Configuration parameters for Adler32 codec."""
269271

272+
location: Literal["start", "end"]
273+
270274

271275
class Adler32JSON_V2(Adler32Config):
272276
"""JSON representation of Adler32 codec for Zarr V2."""
@@ -295,6 +299,9 @@ class Fletcher32JSON_V3(NamedRequiredConfig[Literal["fletcher32"], Fletcher32Con
295299
class JenkinsLookup3Config(TypedDict):
296300
"""Configuration parameters for JenkinsLookup3 codec."""
297301

302+
initval: int
303+
prefix: bytes
304+
298305

299306
class JenkinsLookup3JSON_V2(JenkinsLookup3Config):
300307
"""JSON representation of JenkinsLookup3 codec for Zarr V2."""
@@ -747,7 +754,7 @@ def to_json(self, zarr_format: ZarrFormat) -> Crc32JSON_V2 | Crc32JSON_V3:
747754
class CRC32C(_NumcodecsChecksumCodec):
748755
codec_name = "numcodecs.crc32c"
749756
_codec_id = "crc32c"
750-
codec_config: Crc32cConfig
757+
codec_config: Crc32cConfig_V2
751758

752759
@overload
753760
def to_json(self, zarr_format: Literal[2]) -> Crc32cJSON_V2: ...

0 commit comments

Comments
 (0)