Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions changes/3374.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replaces usage of the ``zarr.core.common.ChunkCoords`` typealias with ``tuple[int, ...]``.
14 changes: 9 additions & 5 deletions src/zarr/abc/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from zarr.abc.metadata import Metadata
from zarr.core.buffer import Buffer, NDBuffer
from zarr.core.common import ChunkCoords, concurrent_map
from zarr.core.common import concurrent_map
from zarr.core.config import config

if TYPE_CHECKING:
Expand Down Expand Up @@ -96,7 +96,7 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
def validate(
self,
*,
shape: ChunkCoords,
shape: tuple[int, ...],
dtype: ZDType[TBaseDType, TBaseScalar],
chunk_grid: ChunkGrid,
) -> None:
Expand All @@ -105,7 +105,7 @@ def validate(

Parameters
----------
shape : ChunkCoords
shape : tuple[int, ...]
The array shape
dtype : np.dtype[Any]
The array data type
Expand Down Expand Up @@ -311,14 +311,18 @@ def supports_partial_encode(self) -> bool: ...

@abstractmethod
def validate(
self, *, shape: ChunkCoords, dtype: ZDType[TBaseDType, TBaseScalar], chunk_grid: ChunkGrid
self,
*,
shape: tuple[int, ...],
dtype: ZDType[TBaseDType, TBaseScalar],
chunk_grid: ChunkGrid,
) -> None:
"""Validates that all codec configurations are compatible with the array metadata.
Raises errors when a codec configuration is not compatible.

Parameters
----------
shape : ChunkCoords
shape : tuple[int, ...]
The array shape
dtype : np.dtype[Any]
The array data type
Expand Down
17 changes: 8 additions & 9 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from zarr.core.common import (
JSON,
AccessModeLiteral,
ChunkCoords,
DimensionNames,
MemoryOrder,
ZarrFormat,
Expand Down Expand Up @@ -107,7 +106,7 @@ def _infer_overwrite(mode: AccessModeLiteral) -> bool:
return mode in _OVERWRITE_MODES


def _get_shape_chunks(a: ArrayLike | Any) -> tuple[ChunkCoords | None, ChunkCoords | None]:
def _get_shape_chunks(a: ArrayLike | Any) -> tuple[tuple[int, ...] | None, tuple[int, ...] | None]:
"""Helper function to get the shape and chunks from an array-like object"""
shape = None
chunks = None
Expand Down Expand Up @@ -865,9 +864,9 @@ async def open_group(


async def create(
shape: ChunkCoords | int,
shape: tuple[int, ...] | int,
*, # Note: this is a change from v2
chunks: ChunkCoords | int | bool | None = None,
chunks: tuple[int, ...] | int | bool | None = None,
dtype: ZDTypeLike | None = None,
compressor: CompressorLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE,
Expand All @@ -889,7 +888,7 @@ async def create(
meta_array: Any | None = None, # TODO: need type
attributes: dict[str, JSON] | None = None,
# v3 only
chunk_shape: ChunkCoords | int | None = None,
chunk_shape: tuple[int, ...] | int | None = None,
chunk_key_encoding: (
ChunkKeyEncoding
| tuple[Literal["default"], Literal[".", "/"]]
Expand Down Expand Up @@ -1074,7 +1073,7 @@ async def create(


async def empty(
shape: ChunkCoords, **kwargs: Any
shape: tuple[int, ...], **kwargs: Any
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
"""Create an empty array with the specified shape. The contents will be filled with the
array's fill value or zeros if no fill value is provided.
Expand Down Expand Up @@ -1126,7 +1125,7 @@ async def empty_like(

# TODO: add type annotations for fill_value and kwargs
async def full(
shape: ChunkCoords, fill_value: Any, **kwargs: Any
shape: tuple[int, ...], fill_value: Any, **kwargs: Any
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
"""Create an array, with `fill_value` being used as the default value for
uninitialized portions of the array.
Expand Down Expand Up @@ -1173,7 +1172,7 @@ async def full_like(


async def ones(
shape: ChunkCoords, **kwargs: Any
shape: tuple[int, ...], **kwargs: Any
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
"""Create an array, with one being used as the default value for
uninitialized portions of the array.
Expand Down Expand Up @@ -1296,7 +1295,7 @@ async def open_like(


async def zeros(
shape: ChunkCoords, **kwargs: Any
shape: tuple[int, ...], **kwargs: Any
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
"""Create an array, with zero being used as the default value for
uninitialized portions of the array.
Expand Down
33 changes: 16 additions & 17 deletions src/zarr/api/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from zarr.core.common import (
JSON,
AccessModeLiteral,
ChunkCoords,
DimensionNames,
MemoryOrder,
ShapeLike,
Expand Down Expand Up @@ -598,9 +597,9 @@ def create_group(

# TODO: add type annotations for kwargs
def create(
shape: ChunkCoords | int,
shape: tuple[int, ...] | int,
*, # Note: this is a change from v2
chunks: ChunkCoords | int | bool | None = None,
chunks: tuple[int, ...] | int | bool | None = None,
dtype: ZDTypeLike | None = None,
compressor: CompressorLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE, # TODO: need type
Expand All @@ -622,7 +621,7 @@ def create(
meta_array: Any | None = None, # TODO: need type
attributes: dict[str, JSON] | None = None,
# v3 only
chunk_shape: ChunkCoords | int | None = None,
chunk_shape: tuple[int, ...] | int | None = None,
chunk_key_encoding: (
ChunkKeyEncoding
| tuple[Literal["default"], Literal[".", "/"]]
Expand Down Expand Up @@ -755,7 +754,7 @@ def create_array(
shape: ShapeLike | None = None,
dtype: ZDTypeLike | None = None,
data: np.ndarray[Any, np.dtype[Any]] | None = None,
chunks: ChunkCoords | Literal["auto"] = "auto",
chunks: tuple[int, ...] | Literal["auto"] = "auto",
shards: ShardsLike | None = None,
filters: FiltersLike = "auto",
compressors: CompressorsLike = "auto",
Expand All @@ -782,18 +781,18 @@ def create_array(
name : str or None, optional
The name of the array within the store. If ``name`` is ``None``, the array will be located
at the root of the store.
shape : ChunkCoords, optional
shape : tuple[int, ...], optional
Shape of the array. Can be ``None`` if ``data`` is provided.
dtype : ZDTypeLike, optional
Data type of the array. Can be ``None`` if ``data`` is provided.
data : np.ndarray, optional
Array-like data to use for initializing the array. If this parameter is provided, the
``shape`` and ``dtype`` parameters must be identical to ``data.shape`` and ``data.dtype``,
or ``None``.
chunks : ChunkCoords, optional
chunks : tuple[int, ...], optional
Chunk shape of the array.
If not specified, default are guessed based on the shape and dtype.
shards : ChunkCoords, optional
shards : tuple[int, ...], optional
Shard shape of the array. The default value of ``None`` results in no sharding at all.
filters : Iterable[Codec], optional
Iterable of filters to apply to each chunk of the array, in order, before serializing that
Expand Down Expand Up @@ -921,7 +920,7 @@ def from_array(
data: Array | npt.ArrayLike,
write_data: bool = True,
name: str | None = None,
chunks: Literal["auto", "keep"] | ChunkCoords = "keep",
chunks: Literal["auto", "keep"] | tuple[int, ...] = "keep",
shards: ShardsLike | None | Literal["keep"] = "keep",
filters: FiltersLike | Literal["keep"] = "keep",
compressors: CompressorsLike | Literal["keep"] = "keep",
Expand Down Expand Up @@ -951,22 +950,22 @@ def from_array(
name : str or None, optional
The name of the array within the store. If ``name`` is ``None``, the array will be located
at the root of the store.
chunks : ChunkCoords or "auto" or "keep", optional
chunks : tuple[int, ...] or "auto" or "keep", optional
Chunk shape of the array.
Following values are supported:

- "auto": Automatically determine the chunk shape based on the array's shape and dtype.
- "keep": Retain the chunk shape of the data array if it is a zarr Array.
- ChunkCoords: A tuple of integers representing the chunk shape.
- tuple[int, ...]: A tuple of integers representing the chunk shape.

If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
shards : ChunkCoords, optional
shards : tuple[int, ...], optional
Shard shape of the array.
Following values are supported:

- "auto": Automatically determine the shard shape based on the array's shape and chunk shape.
- "keep": Retain the shard shape of the data array if it is a zarr Array.
- ChunkCoords: A tuple of integers representing the shard shape.
- tuple[int, ...]: A tuple of integers representing the shard shape.
- None: No sharding.

If not specified, defaults to "keep" if data is a zarr Array, otherwise None.
Expand Down Expand Up @@ -1129,7 +1128,7 @@ def from_array(


# TODO: add type annotations for kwargs
def empty(shape: ChunkCoords, **kwargs: Any) -> Array:
def empty(shape: tuple[int, ...], **kwargs: Any) -> Array:
"""Create an empty array with the specified shape. The contents will be filled with the
array's fill value or zeros if no fill value is provided.

Expand Down Expand Up @@ -1182,7 +1181,7 @@ def empty_like(a: ArrayLike, **kwargs: Any) -> Array:


# TODO: add type annotations for kwargs and fill_value
def full(shape: ChunkCoords, fill_value: Any, **kwargs: Any) -> Array:
def full(shape: tuple[int, ...], fill_value: Any, **kwargs: Any) -> Array:
"""Create an array with a default fill value.

Parameters
Expand Down Expand Up @@ -1223,7 +1222,7 @@ def full_like(a: ArrayLike, **kwargs: Any) -> Array:


# TODO: add type annotations for kwargs
def ones(shape: ChunkCoords, **kwargs: Any) -> Array:
def ones(shape: tuple[int, ...], **kwargs: Any) -> Array:
"""Create an array with a fill value of one.

Parameters
Expand Down Expand Up @@ -1325,7 +1324,7 @@ def open_like(a: ArrayLike, path: str, **kwargs: Any) -> Array:


# TODO: add type annotations for kwargs
def zeros(shape: ChunkCoords, **kwargs: Any) -> Array:
def zeros(shape: tuple[int, ...], **kwargs: Any) -> Array:
"""Create an array with a fill value of zero.

Parameters
Expand Down
Loading
Loading