From 64c4cca70f3b10d7e6a8bead7f415edd451bf66e Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Wed, 8 Oct 2025 20:58:15 -0700 Subject: [PATCH 1/3] chore(crc32c): replace crc32c with google-crc32c dependency --- .pre-commit-config.yaml | 2 +- numcodecs/checksum32.py | 10 ++++++++-- pyproject.toml | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c08b8f8a..723e0a85 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,4 +30,4 @@ repos: hooks: - id: mypy args: [--config-file, pyproject.toml] - additional_dependencies: [numpy, pytest, crc32c, zfpy, 'zarr>=3'] + additional_dependencies: [numpy, pytest, google-crc32c, zfpy, 'zarr>=3'] diff --git a/numcodecs/checksum32.py b/numcodecs/checksum32.py index b7d5bf0b..9ecf212e 100644 --- a/numcodecs/checksum32.py +++ b/numcodecs/checksum32.py @@ -14,7 +14,7 @@ _crc32c: ModuleType | None = None with suppress(ImportError): - import crc32c as _crc32c # type: ignore[no-redef, unused-ignore] + import google_crc32c as _crc32c # type: ignore[no-redef, unused-ignore] CHECKSUM_LOCATION = Literal['start', 'end'] @@ -179,5 +179,11 @@ class CRC32C(Checksum32): """ codec_id = 'crc32c' - checksum = _crc32c.crc32c # type: ignore[union-attr] location = 'end' + + @staticmethod + def checksum(data: Buffer, value: int = 0) -> int: + if value == 0: + return _crc32c.value(data) # type: ignore[union-attr] + else: + return _crc32c.extend(value, data) # type: ignore[union-attr] diff --git a/pyproject.toml b/pyproject.toml index c925cd17..68aef3fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ pcodec = [ "pcodec>=0.3,<0.4", ] crc32c = [ - "crc32c>=2.7", + "google-crc32c>=1.5", ] [project.entry-points."zarr.codecs"] From 61d7e148d26a0c0472e0aa6c6d588819f64721d2 Mon Sep 17 00:00:00 2001 From: Joseph Hamman Date: Wed, 8 Oct 2025 21:26:28 -0700 Subject: [PATCH 2/3] add incremental checksum test --- numcodecs/tests/test_checksum32.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/numcodecs/tests/test_checksum32.py b/numcodecs/tests/test_checksum32.py index 9bdc25cb..b2d91cf0 100644 --- a/numcodecs/tests/test_checksum32.py +++ b/numcodecs/tests/test_checksum32.py @@ -145,6 +145,25 @@ def test_crc32c_checksum(): assert np.frombuffer(buf, dtype=" Date: Fri, 10 Oct 2025 21:54:19 -0700 Subject: [PATCH 3/3] add crc32c to the test environment for compat with existing zarr versions --- .pre-commit-config.yaml | 2 +- pyproject.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 723e0a85..49678a44 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,4 +30,4 @@ repos: hooks: - id: mypy args: [--config-file, pyproject.toml] - additional_dependencies: [numpy, pytest, google-crc32c, zfpy, 'zarr>=3'] + additional_dependencies: [numpy, pytest, google-crc32c, crc32c, zfpy, 'zarr>=3'] diff --git a/pyproject.toml b/pyproject.toml index 68aef3fe..601d3f3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,6 +61,7 @@ test = [ ] test_extras = [ "importlib_metadata", + "crc32c", # TODO: remove once zarr-python does not depend on crc32c anymore ] msgpack = [ "msgpack",