Skip to content
Merged
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
14 changes: 7 additions & 7 deletions src/zarr/abc/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

from zarr.abc.store import ByteGetter, ByteSetter, Store
from zarr.core.array_spec import ArraySpec
from zarr.core.chunk_grids import ChunkGrid
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar, ZDType
from zarr.core.indexing import SelectorTuple
from zarr.core.metadata import ArrayMetadata
from zarr.core.metadata.v3 import ChunkGridMetadata

__all__ = [
"ArrayArrayCodec",
Expand Down Expand Up @@ -140,7 +140,7 @@ def validate(
*,
shape: tuple[int, ...],
dtype: ZDType[TBaseDType, TBaseScalar],
chunk_grid: ChunkGrid,
chunk_grid: ChunkGridMetadata,
) -> None:
"""Validates that the codec configuration is compatible with the array metadata.
Raises errors when the codec configuration is not compatible.
Expand All @@ -151,8 +151,8 @@ def validate(
The array shape
dtype : np.dtype[Any]
The array data type
chunk_grid : ChunkGrid
The array chunk grid
chunk_grid : ChunkGridMetadata
The array chunk grid metadata
"""

async def _decode_single(self, chunk_data: CodecOutput, chunk_spec: ArraySpec) -> CodecInput:
Expand Down Expand Up @@ -357,7 +357,7 @@ def validate(
*,
shape: tuple[int, ...],
dtype: ZDType[TBaseDType, TBaseScalar],
chunk_grid: ChunkGrid,
chunk_grid: ChunkGridMetadata,
) -> None:
"""Validates that all codec configurations are compatible with the array metadata.
Raises errors when a codec configuration is not compatible.
Expand All @@ -368,8 +368,8 @@ def validate(
The array shape
dtype : np.dtype[Any]
The array data type
chunk_grid : ChunkGrid
The array chunk grid
chunk_grid : ChunkGridMetadata
The array chunk grid metadata
"""
...

Expand Down
24 changes: 12 additions & 12 deletions src/zarr/codecs/sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@
get_indexer,
morton_order_iter,
)
from zarr.core.metadata.v3 import parse_codecs
from zarr.core.metadata.v3 import (
ChunkGridMetadata,
RectilinearChunkGrid,
RegularChunkGrid,
parse_codecs,
)
from zarr.registry import get_ndbuffer_class, get_pipeline_class
from zarr.storage._utils import _normalize_byte_range_index

Expand Down Expand Up @@ -381,16 +386,13 @@ def validate(
*,
shape: tuple[int, ...],
dtype: ZDType[TBaseDType, TBaseScalar],
chunk_grid: ChunkGrid,
chunk_grid: ChunkGridMetadata,
) -> None:
if len(self.chunk_shape) != len(shape):
raise ValueError(
"The shard's `chunk_shape` and array's `shape` need to have the same number of dimensions."
)
# Sharding works with both regular and rectilinear outer chunk grids.
# Each shard is self-contained — the ShardingCodec constructs an independent
# inner ChunkGrid per shard using the shard shape and subchunk shape.
if chunk_grid.is_regular:
if isinstance(chunk_grid, RegularChunkGrid):
if not all(
s % c == 0
for s, c in zip(
Expand All @@ -403,15 +405,13 @@ def validate(
f"The array's `chunk_shape` (got {chunk_grid.chunk_shape}) "
f"needs to be divisible by the shard's inner `chunk_shape` (got {self.chunk_shape})."
)
else:
elif isinstance(chunk_grid, RectilinearChunkGrid):
# For rectilinear grids, every unique edge length per dimension
# must be divisible by the corresponding inner chunk size.
# unique_edge_lengths is a lazy generator that short-circuits
# deduplication, and we short-circuit on the first failure.
for i, (dim, inner) in enumerate(
zip(chunk_grid.dimensions, self.chunk_shape, strict=False)
for i, (edges, inner) in enumerate(
zip(chunk_grid.chunk_shapes, self.chunk_shape, strict=False)
):
for edge in dim.unique_edge_lengths:
for edge in set(edges):
if edge % inner != 0:
raise ValueError(
f"Chunk edge length {edge} in dimension {i} is not "
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/codecs/transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from typing import Self

from zarr.core.buffer import NDBuffer
from zarr.core.chunk_grids import ChunkGrid
from zarr.core.dtype.wrapper import TBaseDType, TBaseScalar, ZDType
from zarr.core.metadata.v3 import ChunkGridMetadata


def parse_transpose_order(data: JSON | Iterable[int]) -> tuple[int, ...]:
Expand Down Expand Up @@ -51,7 +51,7 @@ def validate(
self,
shape: tuple[int, ...],
dtype: ZDType[TBaseDType, TBaseScalar],
chunk_grid: ChunkGrid,
chunk_grid: ChunkGridMetadata,
) -> None:
if len(self.order) != len(shape):
raise ValueError(
Expand Down
Loading