Skip to content

Commit 16d1394

Browse files
committed
remove ChunkCoords type
1 parent a26926c commit 16d1394

22 files changed

Lines changed: 255 additions & 251 deletions

src/zarr/abc/codec.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from zarr.abc.metadata import Metadata
77
from zarr.core.buffer import Buffer, NDBuffer
8-
from zarr.core.common import ChunkCoords, concurrent_map
8+
from zarr.core.common import concurrent_map
99
from zarr.core.config import config
1010

1111
if TYPE_CHECKING:
@@ -96,7 +96,7 @@ def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
9696
def validate(
9797
self,
9898
*,
99-
shape: ChunkCoords,
99+
shape: tuple[int, ...],
100100
dtype: ZDType[TBaseDType, TBaseScalar],
101101
chunk_grid: ChunkGrid,
102102
) -> None:
@@ -105,7 +105,7 @@ def validate(
105105
106106
Parameters
107107
----------
108-
shape : ChunkCoords
108+
shape : tuple[int, ...]
109109
The array shape
110110
dtype : np.dtype[Any]
111111
The array data type
@@ -311,14 +311,18 @@ def supports_partial_encode(self) -> bool: ...
311311

312312
@abstractmethod
313313
def validate(
314-
self, *, shape: ChunkCoords, dtype: ZDType[TBaseDType, TBaseScalar], chunk_grid: ChunkGrid
314+
self,
315+
*,
316+
shape: tuple[int, ...],
317+
dtype: ZDType[TBaseDType, TBaseScalar],
318+
chunk_grid: ChunkGrid,
315319
) -> None:
316320
"""Validates that all codec configurations are compatible with the array metadata.
317321
Raises errors when a codec configuration is not compatible.
318322
319323
Parameters
320324
----------
321-
shape : ChunkCoords
325+
shape : tuple[int, ...]
322326
The array shape
323327
dtype : np.dtype[Any]
324328
The array data type

src/zarr/api/asynchronous.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from zarr.core.common import (
2525
JSON,
2626
AccessModeLiteral,
27-
ChunkCoords,
2827
DimensionNames,
2928
MemoryOrder,
3029
ZarrFormat,
@@ -107,7 +106,7 @@ def _infer_overwrite(mode: AccessModeLiteral) -> bool:
107106
return mode in _OVERWRITE_MODES
108107

109108

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

866865

867866
async def create(
868-
shape: ChunkCoords | int,
867+
shape: tuple[int, ...] | int,
869868
*, # Note: this is a change from v2
870-
chunks: ChunkCoords | int | bool | None = None,
869+
chunks: tuple[int, ...] | int | bool | None = None,
871870
dtype: ZDTypeLike | None = None,
872871
compressor: CompressorLike = "auto",
873872
fill_value: Any | None = DEFAULT_FILL_VALUE,
@@ -889,7 +888,7 @@ async def create(
889888
meta_array: Any | None = None, # TODO: need type
890889
attributes: dict[str, JSON] | None = None,
891890
# v3 only
892-
chunk_shape: ChunkCoords | int | None = None,
891+
chunk_shape: tuple[int, ...] | int | None = None,
893892
chunk_key_encoding: (
894893
ChunkKeyEncoding
895894
| tuple[Literal["default"], Literal[".", "/"]]
@@ -1074,7 +1073,7 @@ async def create(
10741073

10751074

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

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

11741173

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

12971296

12981297
async def zeros(
1299-
shape: ChunkCoords, **kwargs: Any
1298+
shape: tuple[int, ...], **kwargs: Any
13001299
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
13011300
"""Create an array, with zero being used as the default value for
13021301
uninitialized portions of the array.

src/zarr/api/synchronous.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from zarr.core.common import (
3434
JSON,
3535
AccessModeLiteral,
36-
ChunkCoords,
3736
DimensionNames,
3837
MemoryOrder,
3938
ShapeLike,
@@ -598,9 +597,9 @@ def create_group(
598597

599598
# TODO: add type annotations for kwargs
600599
def create(
601-
shape: ChunkCoords | int,
600+
shape: tuple[int, ...] | int,
602601
*, # Note: this is a change from v2
603-
chunks: ChunkCoords | int | bool | None = None,
602+
chunks: tuple[int, ...] | int | bool | None = None,
604603
dtype: ZDTypeLike | None = None,
605604
compressor: CompressorLike = "auto",
606605
fill_value: Any | None = DEFAULT_FILL_VALUE, # TODO: need type
@@ -622,7 +621,7 @@ def create(
622621
meta_array: Any | None = None, # TODO: need type
623622
attributes: dict[str, JSON] | None = None,
624623
# v3 only
625-
chunk_shape: ChunkCoords | int | None = None,
624+
chunk_shape: tuple[int, ...] | int | None = None,
626625
chunk_key_encoding: (
627626
ChunkKeyEncoding
628627
| tuple[Literal["default"], Literal[".", "/"]]
@@ -755,7 +754,7 @@ def create_array(
755754
shape: ShapeLike | None = None,
756755
dtype: ZDTypeLike | None = None,
757756
data: np.ndarray[Any, np.dtype[Any]] | None = None,
758-
chunks: ChunkCoords | Literal["auto"] = "auto",
757+
chunks: tuple[int, ...] | Literal["auto"] = "auto",
759758
shards: ShardsLike | None = None,
760759
filters: FiltersLike = "auto",
761760
compressors: CompressorsLike = "auto",
@@ -782,18 +781,18 @@ def create_array(
782781
name : str or None, optional
783782
The name of the array within the store. If ``name`` is ``None``, the array will be located
784783
at the root of the store.
785-
shape : ChunkCoords, optional
784+
shape : tuple[int, ...], optional
786785
Shape of the array. Can be ``None`` if ``data`` is provided.
787786
dtype : ZDTypeLike, optional
788787
Data type of the array. Can be ``None`` if ``data`` is provided.
789788
data : np.ndarray, optional
790789
Array-like data to use for initializing the array. If this parameter is provided, the
791790
``shape`` and ``dtype`` parameters must be identical to ``data.shape`` and ``data.dtype``,
792791
or ``None``.
793-
chunks : ChunkCoords, optional
792+
chunks : tuple[int, ...], optional
794793
Chunk shape of the array.
795794
If not specified, default are guessed based on the shape and dtype.
796-
shards : ChunkCoords, optional
795+
shards : tuple[int, ...], optional
797796
Shard shape of the array. The default value of ``None`` results in no sharding at all.
798797
filters : Iterable[Codec], optional
799798
Iterable of filters to apply to each chunk of the array, in order, before serializing that
@@ -921,7 +920,7 @@ def from_array(
921920
data: Array | npt.ArrayLike,
922921
write_data: bool = True,
923922
name: str | None = None,
924-
chunks: Literal["auto", "keep"] | ChunkCoords = "keep",
923+
chunks: Literal["auto", "keep"] | tuple[int, ...] = "keep",
925924
shards: ShardsLike | None | Literal["keep"] = "keep",
926925
filters: FiltersLike | Literal["keep"] = "keep",
927926
compressors: CompressorsLike | Literal["keep"] = "keep",
@@ -951,22 +950,22 @@ def from_array(
951950
name : str or None, optional
952951
The name of the array within the store. If ``name`` is ``None``, the array will be located
953952
at the root of the store.
954-
chunks : ChunkCoords or "auto" or "keep", optional
953+
chunks : tuple[int, ...] or "auto" or "keep", optional
955954
Chunk shape of the array.
956955
Following values are supported:
957956
958957
- "auto": Automatically determine the chunk shape based on the array's shape and dtype.
959958
- "keep": Retain the chunk shape of the data array if it is a zarr Array.
960-
- ChunkCoords: A tuple of integers representing the chunk shape.
959+
- tuple[int, ...]: A tuple of integers representing the chunk shape.
961960
962961
If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
963-
shards : ChunkCoords, optional
962+
shards : tuple[int, ...], optional
964963
Shard shape of the array.
965964
Following values are supported:
966965
967966
- "auto": Automatically determine the shard shape based on the array's shape and chunk shape.
968967
- "keep": Retain the shard shape of the data array if it is a zarr Array.
969-
- ChunkCoords: A tuple of integers representing the shard shape.
968+
- tuple[int, ...]: A tuple of integers representing the shard shape.
970969
- None: No sharding.
971970
972971
If not specified, defaults to "keep" if data is a zarr Array, otherwise None.
@@ -1129,7 +1128,7 @@ def from_array(
11291128

11301129

11311130
# TODO: add type annotations for kwargs
1132-
def empty(shape: ChunkCoords, **kwargs: Any) -> Array:
1131+
def empty(shape: tuple[int, ...], **kwargs: Any) -> Array:
11331132
"""Create an empty array with the specified shape. The contents will be filled with the
11341133
array's fill value or zeros if no fill value is provided.
11351134
@@ -1182,7 +1181,7 @@ def empty_like(a: ArrayLike, **kwargs: Any) -> Array:
11821181

11831182

11841183
# TODO: add type annotations for kwargs and fill_value
1185-
def full(shape: ChunkCoords, fill_value: Any, **kwargs: Any) -> Array:
1184+
def full(shape: tuple[int, ...], fill_value: Any, **kwargs: Any) -> Array:
11861185
"""Create an array with a default fill value.
11871186
11881187
Parameters
@@ -1223,7 +1222,7 @@ def full_like(a: ArrayLike, **kwargs: Any) -> Array:
12231222

12241223

12251224
# TODO: add type annotations for kwargs
1226-
def ones(shape: ChunkCoords, **kwargs: Any) -> Array:
1225+
def ones(shape: tuple[int, ...], **kwargs: Any) -> Array:
12271226
"""Create an array with a fill value of one.
12281227
12291228
Parameters
@@ -1325,7 +1324,7 @@ def open_like(a: ArrayLike, path: str, **kwargs: Any) -> Array:
13251324

13261325

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

0 commit comments

Comments
 (0)