Skip to content

Commit 0dc7dc6

Browse files
committed
merge
2 parents 1643983 + 5cdb515 commit 0dc7dc6

File tree

8 files changed

+81
-86
lines changed

8 files changed

+81
-86
lines changed

src/zarr/api/asynchronous.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing_extensions import deprecated
1111

1212
from zarr.core.array import Array, AsyncArray, create_array, get_array_metadata
13-
from zarr.core.array_spec import ArrayConfig, ArrayConfigParams
13+
from zarr.core.array_spec import ArrayConfig, ArrayConfigLike
1414
from zarr.core.buffer import NDArrayLike
1515
from zarr.core.common import (
1616
JSON,
@@ -859,7 +859,7 @@ async def create(
859859
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
860860
dimension_names: Iterable[str] | None = None,
861861
storage_options: dict[str, Any] | None = None,
862-
config: ArrayConfig | ArrayConfigParams | None = None,
862+
config: ArrayConfig | ArrayConfigLike | None = None,
863863
**kwargs: Any,
864864
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
865865
"""Create an array.
@@ -961,7 +961,7 @@ async def create(
961961
storage_options : dict
962962
If using an fsspec URL to create the store, these will be passed to
963963
the backend implementation. Ignored otherwise.
964-
config : ArrayConfig or ArrayConfigParams, optional
964+
config : ArrayConfig or ArrayConfigLike, optional
965965
Runtime configuration of the array. If provided, will override the
966966
default values from `zarr.config.array`.
967967
@@ -1020,7 +1020,7 @@ async def create(
10201020
mode = "a"
10211021
store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options)
10221022

1023-
config_dict: ArrayConfigParams = {}
1023+
config_dict: ArrayConfigLike = {}
10241024

10251025
if write_empty_chunks is not None:
10261026
if config is not None:

src/zarr/api/synchronous.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@
1818

1919
from zarr.abc.codec import Codec
2020
from zarr.api.asynchronous import ArrayLike, PathLike
21-
from zarr.core.array import (
22-
CompressorsParam,
23-
FiltersParam,
24-
SerializerParam,
25-
ShardsParam,
26-
)
27-
from zarr.core.array_spec import ArrayConfig, ArrayConfigParams
21+
from zarr.core.array import CompressorsLike, FiltersLike, SerializerLike, ShardsLike
22+
from zarr.core.array_spec import ArrayConfig, ArrayConfigLike
2823
from zarr.core.buffer import NDArrayLike
29-
from zarr.core.chunk_key_encodings import ChunkKeyEncoding, ChunkKeyEncodingParams
24+
from zarr.core.chunk_key_encodings import ChunkKeyEncoding, ChunkKeyEncodingLike
3025
from zarr.core.common import (
3126
JSON,
3227
AccessModeLiteral,
@@ -622,7 +617,7 @@ def create(
622617
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
623618
dimension_names: Iterable[str] | None = None,
624619
storage_options: dict[str, Any] | None = None,
625-
config: ArrayConfig | ArrayConfigParams | None = None,
620+
config: ArrayConfig | ArrayConfigLike | None = None,
626621
**kwargs: Any,
627622
) -> Array:
628623
"""Create an array.
@@ -692,7 +687,7 @@ def create(
692687
storage_options : dict
693688
If using an fsspec URL to create the store, these will be passed to
694689
the backend implementation. Ignored otherwise.
695-
config : ArrayConfig or ArrayConfigParams, optional
690+
config : ArrayConfig or ArrayConfigLike, optional
696691
Runtime configuration of the array. If provided, will override the
697692
default values from `zarr.config.array`.
698693
@@ -745,21 +740,21 @@ def create_array(
745740
shape: ShapeLike,
746741
dtype: npt.DTypeLike,
747742
chunks: ChunkCoords | Literal["auto"] = "auto",
748-
shards: ShardsParam | None = None,
749-
filters: FiltersParam | None = "auto",
750-
compressors: CompressorsParam = "auto",
751-
serializer: SerializerParam = "auto",
743+
shards: ShardsLike | None = None,
744+
filters: FiltersLike = "auto",
745+
compressors: CompressorsLike = "auto",
746+
serializer: SerializerLike = "auto",
752747
fill_value: Any | None = None,
753748
order: MemoryOrder | None = None,
754749
zarr_format: ZarrFormat | None = 3,
755750
attributes: dict[str, JSON] | None = None,
756-
chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingParams | None = None,
751+
chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingLike | None = None,
757752
dimension_names: Iterable[str] | None = None,
758753
storage_options: dict[str, Any] | None = None,
759754
overwrite: bool = False,
760-
config: ArrayConfig | ArrayConfigParams | None = None,
755+
config: ArrayConfig | ArrayConfigLike | None = None,
761756
) -> Array:
762-
"""Create an array.
757+
"""Create an ``Array``. This function wraps :mod:`zarr.core.array.create_array`.
763758
764759
Parameters
765760
----------
@@ -844,7 +839,7 @@ def create_array(
844839
Ignored otherwise.
845840
overwrite : bool, default False
846841
Whether to overwrite an array with the same name in the store, if one exists.
847-
config : ArrayConfig or ArrayConfigParams, optional
842+
config : ArrayConfig or ArrayConfigLike, optional
848843
Runtime configuration for the array.
849844
850845
Returns
@@ -867,7 +862,7 @@ def create_array(
867862
return Array(
868863
sync(
869864
zarr.core.array.create_array(
870-
store=store,
865+
store,
871866
name=name,
872867
shape=shape,
873868
dtype=dtype,

src/zarr/core/array.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from zarr.abc.store import Store, set_or_delete
3030
from zarr.codecs._v2 import V2Codec
3131
from zarr.core._info import ArrayInfo
32-
from zarr.core.array_spec import ArrayConfig, ArrayConfigParams, parse_array_config
32+
from zarr.core.array_spec import ArrayConfig, ArrayConfigLike, parse_array_config
3333
from zarr.core.attributes import Attributes
3434
from zarr.core.buffer import (
3535
BufferPrototype,
@@ -40,7 +40,7 @@
4040
from zarr.core.chunk_grids import RegularChunkGrid, _auto_partition, normalize_chunks
4141
from zarr.core.chunk_key_encodings import (
4242
ChunkKeyEncoding,
43-
ChunkKeyEncodingParams,
43+
ChunkKeyEncodingLike,
4444
DefaultChunkKeyEncoding,
4545
V2ChunkKeyEncoding,
4646
)
@@ -302,7 +302,7 @@ async def create(
302302
# runtime
303303
overwrite: bool = False,
304304
data: npt.ArrayLike | None = None,
305-
config: ArrayConfig | ArrayConfigParams | None = None,
305+
config: ArrayConfig | ArrayConfigLike | None = None,
306306
) -> AsyncArray[ArrayV2Metadata]: ...
307307

308308
# this overload defines the function signature when zarr_format is 3
@@ -331,7 +331,7 @@ async def create(
331331
# runtime
332332
overwrite: bool = False,
333333
data: npt.ArrayLike | None = None,
334-
config: ArrayConfig | ArrayConfigParams | None = None,
334+
config: ArrayConfig | ArrayConfigLike | None = None,
335335
) -> AsyncArray[ArrayV3Metadata]: ...
336336

337337
@overload
@@ -359,7 +359,7 @@ async def create(
359359
# runtime
360360
overwrite: bool = False,
361361
data: npt.ArrayLike | None = None,
362-
config: ArrayConfig | ArrayConfigParams | None = None,
362+
config: ArrayConfig | ArrayConfigLike | None = None,
363363
) -> AsyncArray[ArrayV3Metadata]: ...
364364

365365
@overload
@@ -393,7 +393,7 @@ async def create(
393393
# runtime
394394
overwrite: bool = False,
395395
data: npt.ArrayLike | None = None,
396-
config: ArrayConfig | ArrayConfigParams | None = None,
396+
config: ArrayConfig | ArrayConfigLike | None = None,
397397
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]: ...
398398

399399
@classmethod
@@ -428,7 +428,7 @@ async def create(
428428
# runtime
429429
overwrite: bool = False,
430430
data: npt.ArrayLike | None = None,
431-
config: ArrayConfig | ArrayConfigParams | None = None,
431+
config: ArrayConfig | ArrayConfigLike | None = None,
432432
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
433433
"""Method to create a new asynchronous array instance.
434434
@@ -502,7 +502,7 @@ async def create(
502502
Whether to raise an error if the store already exists (default is False).
503503
data : npt.ArrayLike, optional
504504
The data to be inserted into the array (default is None).
505-
config : ArrayConfig or ArrayConfigParams, optional
505+
config : ArrayConfig or ArrayConfigLike, optional
506506
Runtime configuration for the array.
507507
508508
Returns
@@ -568,7 +568,7 @@ async def _create(
568568
# runtime
569569
overwrite: bool = False,
570570
data: npt.ArrayLike | None = None,
571-
config: ArrayConfig | ArrayConfigParams | None = None,
571+
config: ArrayConfig | ArrayConfigLike | None = None,
572572
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
573573
"""Method to create a new asynchronous array instance.
574574
See :func:`AsyncArray.create` for more details.
@@ -1633,7 +1633,7 @@ def create(
16331633
compressor: dict[str, JSON] | None = None,
16341634
# runtime
16351635
overwrite: bool = False,
1636-
config: ArrayConfig | ArrayConfigParams | None = None,
1636+
config: ArrayConfig | ArrayConfigLike | None = None,
16371637
) -> Array:
16381638
"""Creates a new Array instance from an initialized store.
16391639
@@ -1761,7 +1761,7 @@ def _create(
17611761
compressor: dict[str, JSON] | None = None,
17621762
# runtime
17631763
overwrite: bool = False,
1764-
config: ArrayConfig | ArrayConfigParams | None = None,
1764+
config: ArrayConfig | ArrayConfigLike | None = None,
17651765
) -> Array:
17661766
"""Creates a new Array instance from an initialized store.
17671767
See :func:`Array.create` for more details.
@@ -3628,30 +3628,30 @@ def _get_default_codecs(
36283628
return cast(list[dict[str, JSON]], default_codecs[dtype_key])
36293629

36303630

3631-
FiltersParam: TypeAlias = (
3632-
Iterable[dict[str, JSON] | ArrayArrayCodec]
3631+
FiltersLike: TypeAlias = (
3632+
Iterable[dict[str, JSON] | ArrayArrayCodec | numcodecs.abc.Codec]
36333633
| ArrayArrayCodec
36343634
| Iterable[numcodecs.abc.Codec]
36353635
| numcodecs.abc.Codec
36363636
| Literal["auto"]
36373637
| None
36383638
)
3639-
CompressorsParam: TypeAlias = (
3639+
CompressorsLike: TypeAlias = (
36403640
Iterable[dict[str, JSON] | BytesBytesCodec]
36413641
| BytesBytesCodec
36423642
| numcodecs.abc.Codec
36433643
| Literal["auto"]
36443644
| None
36453645
)
3646-
SerializerParam: TypeAlias = dict[str, JSON] | ArrayBytesCodec | Literal["auto"]
3646+
SerializerLike: TypeAlias = dict[str, JSON] | ArrayBytesCodec | Literal["auto"]
36473647

36483648

36493649
class ShardsConfigParam(TypedDict):
36503650
shape: ChunkCoords
36513651
index_location: ShardingCodecIndexLocation | None
36523652

36533653

3654-
ShardsParam: TypeAlias = ChunkCoords | ShardsConfigParam | Literal["auto"]
3654+
ShardsLike: TypeAlias = ChunkCoords | ShardsConfigParam | Literal["auto"]
36553655

36563656

36573657
async def create_array(
@@ -3661,21 +3661,21 @@ async def create_array(
36613661
shape: ShapeLike,
36623662
dtype: npt.DTypeLike,
36633663
chunks: ChunkCoords | Literal["auto"] = "auto",
3664-
shards: ShardsParam | None = None,
3665-
filters: FiltersParam | None = "auto",
3666-
compressors: CompressorsParam = "auto",
3667-
serializer: SerializerParam = "auto",
3664+
shards: ShardsLike | None = None,
3665+
filters: FiltersLike = "auto",
3666+
compressors: CompressorsLike = "auto",
3667+
serializer: SerializerLike = "auto",
36683668
fill_value: Any | None = None,
36693669
order: MemoryOrder | None = None,
36703670
zarr_format: ZarrFormat | None = 3,
36713671
attributes: dict[str, JSON] | None = None,
3672-
chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingParams | None = None,
3672+
chunk_key_encoding: ChunkKeyEncoding | ChunkKeyEncodingLike | None = None,
36733673
dimension_names: Iterable[str] | None = None,
36743674
storage_options: dict[str, Any] | None = None,
36753675
overwrite: bool = False,
3676-
config: ArrayConfig | ArrayConfigParams | None = None,
3676+
config: ArrayConfig | ArrayConfigLike | None = None,
36773677
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
3678-
"""Create an array.
3678+
"""Create an ``AsyncArray``.
36793679
36803680
Parameters
36813681
----------
@@ -3760,7 +3760,7 @@ async def create_array(
37603760
Ignored otherwise.
37613761
overwrite : bool, default False
37623762
Whether to overwrite an array with the same name in the store, if one exists.
3763-
config : ArrayConfig or ArrayConfigParams, optional
3763+
config : ArrayConfig or ArrayConfigLike, optional
37643764
Runtime configuration for the array.
37653765
37663766
Returns
@@ -3883,7 +3883,7 @@ async def create_array(
38833883

38843884

38853885
def _parse_chunk_key_encoding(
3886-
data: ChunkKeyEncoding | ChunkKeyEncodingParams | None, zarr_format: ZarrFormat
3886+
data: ChunkKeyEncoding | ChunkKeyEncodingLike | None, zarr_format: ZarrFormat
38873887
) -> ChunkKeyEncoding:
38883888
"""
38893889
Take an implicit specification of a chunk key encoding and parse it into a ChunkKeyEncoding object.
@@ -3971,8 +3971,8 @@ def _get_default_chunk_encoding_v2(
39713971

39723972
def _parse_chunk_encoding_v2(
39733973
*,
3974-
compressor: CompressorsParam,
3975-
filters: FiltersParam | None,
3974+
compressor: CompressorsLike,
3975+
filters: FiltersLike,
39763976
dtype: np.dtype[Any],
39773977
) -> tuple[tuple[numcodecs.abc.Codec, ...] | None, numcodecs.abc.Codec | None]:
39783978
"""
@@ -4015,9 +4015,9 @@ def _parse_chunk_encoding_v2(
40154015

40164016
def _parse_chunk_encoding_v3(
40174017
*,
4018-
compressors: CompressorsParam | None,
4019-
filters: FiltersParam | None,
4020-
serializer: SerializerParam,
4018+
compressors: CompressorsLike,
4019+
filters: FiltersLike,
4020+
serializer: SerializerLike,
40214021
dtype: np.dtype[Any],
40224022
) -> tuple[tuple[ArrayArrayCodec, ...], ArrayBytesCodec, tuple[BytesBytesCodec, ...]]:
40234023
"""

src/zarr/core/array_spec.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from zarr.core.common import ChunkCoords
2222

2323

24-
class ArrayConfigParams(TypedDict):
24+
class ArrayConfigLike(TypedDict):
2525
"""
2626
A TypedDict model of the attributes of an ArrayConfig class, but with no required fields.
2727
This allows for partial construction of an ArrayConfig, with the assumption that the unset
@@ -56,13 +56,13 @@ def __init__(self, order: MemoryOrder, write_empty_chunks: bool) -> None:
5656
object.__setattr__(self, "write_empty_chunks", write_empty_chunks_parsed)
5757

5858
@classmethod
59-
def from_dict(cls, data: ArrayConfigParams) -> Self:
59+
def from_dict(cls, data: ArrayConfigLike) -> Self:
6060
"""
6161
Create an ArrayConfig from a dict. The keys of that dict are a subset of the
6262
attributes of the ArrayConfig class. Any keys missing from that dict will be set to the
6363
the values in the ``array`` namespace of ``zarr.config``.
6464
"""
65-
kwargs_out: ArrayConfigParams = {}
65+
kwargs_out: ArrayConfigLike = {}
6666
for f in fields(ArrayConfig):
6767
field_name = cast(Literal["order", "write_empty_chunks"], f.name)
6868
if field_name not in data:
@@ -72,7 +72,7 @@ def from_dict(cls, data: ArrayConfigParams) -> Self:
7272
return cls(**kwargs_out)
7373

7474

75-
def parse_array_config(data: ArrayConfig | ArrayConfigParams | None) -> ArrayConfig:
75+
def parse_array_config(data: ArrayConfig | ArrayConfigLike | None) -> ArrayConfig:
7676
"""
7777
Convert various types of data to an ArrayConfig.
7878
"""

src/zarr/core/chunk_grids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from collections.abc import Iterator
2828
from typing import Self
2929

30-
from zarr.core.array import ShardsParam
30+
from zarr.core.array import ShardsLike
3131

3232

3333
def _guess_chunks(
@@ -203,7 +203,7 @@ def _auto_partition(
203203
*,
204204
array_shape: tuple[int, ...],
205205
chunk_shape: tuple[int, ...] | Literal["auto"],
206-
shard_shape: ShardsParam | None,
206+
shard_shape: ShardsLike | None,
207207
dtype: np.dtype[Any],
208208
) -> tuple[tuple[int, ...] | None, tuple[int, ...]]:
209209
"""

src/zarr/core/chunk_key_encodings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def parse_separator(data: JSON) -> SeparatorLiteral:
2020
return cast(SeparatorLiteral, data)
2121

2222

23-
class ChunkKeyEncodingParams(TypedDict):
23+
class ChunkKeyEncodingLike(TypedDict):
2424
name: Literal["v2", "default"]
2525
separator: SeparatorLiteral
2626

@@ -37,7 +37,7 @@ def __init__(self, *, separator: SeparatorLiteral) -> None:
3737

3838
@classmethod
3939
def from_dict(
40-
cls, data: dict[str, JSON] | ChunkKeyEncoding | ChunkKeyEncodingParams
40+
cls, data: dict[str, JSON] | ChunkKeyEncoding | ChunkKeyEncodingLike
4141
) -> ChunkKeyEncoding:
4242
if isinstance(data, ChunkKeyEncoding):
4343
return data

0 commit comments

Comments
 (0)