Skip to content
Closed
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
44 changes: 27 additions & 17 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1444,50 +1444,50 @@ def _iter_shard_coords(
selection_shape=selection_shape,
)

def _iter_shard_keys(
def _iter_chunk_regions(
self, *, origin: Sequence[int] | None = None, selection_shape: Sequence[int] | None = None
) -> Iterator[str]:
) -> Iterator[tuple[slice, ...]]:
"""
Iterate over the keys of the stored objects supporting this array.
Iterate over the regions spanned by each chunk.

Parameters
----------
origin : Sequence[int] | None, default=None
The origin of the selection relative to the array's chunk grid.
selection_shape : Sequence[int] | None, default=None
The shape of the selection in shard grid coordinates.
The shape of the selection in chunk grid coordinates.

Yields
------
key: str
The storage key of each chunk in the selection.
region: tuple[slice, ...]
A tuple of slice objects representing the region spanned by each chunk in the selection.
"""
# Iterate over the coordinates of chunks in chunk grid space.
return _iter_shard_keys(
return _iter_chunk_regions(
array=self,
origin=origin,
selection_shape=selection_shape,
)

def _iter_chunk_regions(
def _iter_shard_keys(
self, *, origin: Sequence[int] | None = None, selection_shape: Sequence[int] | None = None
) -> Iterator[tuple[slice, ...]]:
) -> Iterator[str]:
"""
Iterate over the regions spanned by each chunk.
Iterate over the keys of the stored objects supporting this array.

Parameters
----------
origin : Sequence[int] | None, default=None
The origin of the selection relative to the array's chunk grid.
selection_shape : Sequence[int] | None, default=None
The shape of the selection in chunk grid coordinates.
The shape of the selection in shard grid coordinates.

Yields
------
region: tuple[slice, ...]
A tuple of slice objects representing the region spanned by each chunk in the selection.
key: str
The storage key of each chunk in the selection.
"""
return _iter_chunk_regions(
# Iterate over the coordinates of chunks in chunk grid space.
return _iter_shard_keys(
array=self,
origin=origin,
selection_shape=selection_shape,
Expand All @@ -1499,6 +1499,8 @@ def _iter_shard_regions(
"""
Iterate over the regions spanned by each shard.

If no shards are present, then it will fall back on chunks.

Parameters
----------
origin : Sequence[int] | None, default=None
Expand Down Expand Up @@ -2643,6 +2645,9 @@ def _iter_shard_coords(
ranging from `[origin, origin selection_shape]`, where the upper bound is exclusive as
per python indexing conventions.

If no shard grid space is available, e.g., like in zarr version 2, the method will fall back
to chunk grid space.

Parameters
----------
origin : Sequence[int] | None, default=None
Expand Down Expand Up @@ -2683,6 +2688,8 @@ def _iter_shard_regions(
"""
Iterate over the regions spanned by each shard.

If no shard is present, then it will fall back on chunks.

Parameters
----------
origin : Sequence[int] | None, default=None
Expand Down Expand Up @@ -5396,7 +5403,9 @@ def _iter_shard_coords(
chunk_coords: tuple[int, ...]
The coordinates of each shard in the selection.
"""
return _iter_grid(array._shard_grid_shape, origin=origin, selection_shape=selection_shape)
if array._shard_grid_shape:
return _iter_grid(array._shard_grid_shape, origin=origin, selection_shape=selection_shape)
return _iter_grid(array._chunk_grid_shape, origin=origin, selection_shape=selection_shape)


def _iter_shard_keys(
Expand Down Expand Up @@ -5437,7 +5446,8 @@ def _iter_shard_regions(
"""
Iterate over the regions spanned by each shard.

These are the smallest regions of the array that are safe to write concurrently.
These are the smallest regions of the array that are safe to write concurrently. If no shards
are present it will fall back on chunks.

Parameters
----------
Expand Down