Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ repos:
# Package dependencies
- packaging
- donfig
- numcodecs[crc32c]
- numcodecs
- google-crc32c>=1.5
- numpy==2.1 # until https://github.com/numpy/numpy/issues/28034 is resolved
- typing_extensions
- universal-pathlib
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ requires-python = ">=3.11"
dependencies = [
'packaging>=22.0',
'numpy>=1.26',
'numcodecs[crc32c]>=0.14',
'numcodecs>=0.14',
'google-crc32c>=1.5',
'typing_extensions>=4.9',
'donfig>=0.8',
]
Expand Down
8 changes: 5 additions & 3 deletions src/zarr/codecs/crc32c_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, cast

import google_crc32c
import numpy as np
import typing_extensions
from crc32c import crc32c

from zarr.abc.codec import BytesBytesCodec
from zarr.core.common import JSON, parse_named_configuration
Expand Down Expand Up @@ -42,7 +42,7 @@ async def _decode_single(

# Need to do a manual cast until https://github.com/numpy/numpy/issues/26783 is resolved
computed_checksum = np.uint32(
crc32c(cast("typing_extensions.Buffer", inner_bytes))
google_crc32c.value(cast("typing_extensions.Buffer", inner_bytes))
).tobytes()
stored_checksum = bytes(crc32_bytes)
if computed_checksum != stored_checksum:
Expand All @@ -58,7 +58,9 @@ async def _encode_single(
) -> Buffer | None:
data = chunk_bytes.as_numpy_array()
# Calculate the checksum and "cast" it to a numpy array
checksum = np.array([crc32c(cast("typing_extensions.Buffer", data))], dtype=np.uint32)
checksum = np.array(
[google_crc32c.value(cast("typing_extensions.Buffer", data))], dtype=np.uint32
)
# Append the checksum (as bytes) to the data
return chunk_spec.prototype.buffer.from_array_like(np.append(data, checksum.view("B")))

Expand Down
Loading