|
3 | 3 | import asyncio
|
4 | 4 | import dataclasses
|
5 | 5 | import warnings
|
6 |
| -from typing import TYPE_CHECKING, Any, Literal, cast |
| 6 | +from typing import TYPE_CHECKING, Any, Literal, NotRequired, TypedDict, cast |
7 | 7 |
|
8 | 8 | import numpy as np
|
9 | 9 | import numpy.typing as npt
|
|
38 | 38 | create_hierarchy,
|
39 | 39 | )
|
40 | 40 | from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
|
41 |
| -from zarr.core.metadata.v2 import _default_compressor, _default_filters |
| 41 | +from zarr.core.metadata.v2 import CompressorLikev2, _default_compressor, _default_filters |
42 | 42 | from zarr.errors import NodeTypeValidationError
|
43 | 43 | from zarr.storage._common import make_store_path
|
44 | 44 |
|
45 | 45 | if TYPE_CHECKING:
|
46 | 46 | from collections.abc import Iterable
|
47 | 47 |
|
| 48 | + import numcodecs |
| 49 | + |
48 | 50 | from zarr.abc.codec import Codec
|
49 | 51 | from zarr.core.buffer import NDArrayLikeOrScalar
|
50 | 52 | from zarr.core.chunk_key_encodings import ChunkKeyEncoding
|
@@ -116,10 +118,20 @@ def _get_shape_chunks(a: ArrayLike | Any) -> tuple[ChunkCoords | None, ChunkCoor
|
116 | 118 | return shape, chunks
|
117 | 119 |
|
118 | 120 |
|
119 |
| -def _like_args(a: ArrayLike) -> dict[str, object]: |
| 121 | +class _LikeArgs(TypedDict): |
| 122 | + shape: NotRequired[ChunkCoords] |
| 123 | + chunks: NotRequired[ChunkCoords] |
| 124 | + dtype: NotRequired[np.dtype[np.generic]] |
| 125 | + order: NotRequired[Literal["C", "F"]] |
| 126 | + filters: NotRequired[tuple[numcodecs.abc.Codec, ...] | None] |
| 127 | + compressor: NotRequired[CompressorLikev2] |
| 128 | + codecs: NotRequired[tuple[Codec, ...]] |
| 129 | + |
| 130 | + |
| 131 | +def _like_args(a: ArrayLike) -> _LikeArgs: |
120 | 132 | """Set default values for shape and chunks if they are not present in the array-like object"""
|
121 | 133 |
|
122 |
| - new: dict[str, object] = {} |
| 134 | + new: _LikeArgs = {} |
123 | 135 |
|
124 | 136 | shape, chunks = _get_shape_chunks(a)
|
125 | 137 | if shape is not None:
|
|
0 commit comments