|
4 | 4 | from asyncio import gather |
5 | 5 | from dataclasses import dataclass, field, replace |
6 | 6 | from logging import getLogger |
7 | | -from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, cast |
| 7 | +from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar, cast, overload |
8 | 8 |
|
9 | 9 | import numpy as np |
10 | 10 | import numpy.typing as npt |
@@ -191,6 +191,72 @@ def __init__( |
191 | 191 | object.__setattr__(self, "order", order_parsed) |
192 | 192 | object.__setattr__(self, "codec_pipeline", create_codec_pipeline(metadata=metadata_parsed)) |
193 | 193 |
|
| 194 | + @overload |
| 195 | + @classmethod |
| 196 | + async def create( |
| 197 | + cls, |
| 198 | + store: StoreLike, |
| 199 | + *, |
| 200 | + # v2 and v3 |
| 201 | + shape: ShapeLike, |
| 202 | + dtype: npt.DTypeLike, |
| 203 | + zarr_format: Literal[2], |
| 204 | + fill_value: Any | None = None, |
| 205 | + attributes: dict[str, JSON] | None = None, |
| 206 | + # v3 only |
| 207 | + chunk_shape: ChunkCoords | None = None, |
| 208 | + chunk_key_encoding: ( |
| 209 | + ChunkKeyEncoding |
| 210 | + | tuple[Literal["default"], Literal[".", "/"]] |
| 211 | + | tuple[Literal["v2"], Literal[".", "/"]] |
| 212 | + | None |
| 213 | + ) = None, |
| 214 | + codecs: Iterable[Codec | dict[str, JSON]] | None = None, |
| 215 | + dimension_names: Iterable[str] | None = None, |
| 216 | + # v2 only |
| 217 | + chunks: ShapeLike | None = None, |
| 218 | + dimension_separator: Literal[".", "/"] | None = None, |
| 219 | + order: Literal["C", "F"] | None = None, |
| 220 | + filters: list[dict[str, JSON]] | None = None, |
| 221 | + compressor: dict[str, JSON] | None = None, |
| 222 | + # runtime |
| 223 | + exists_ok: bool = False, |
| 224 | + data: npt.ArrayLike | None = None, |
| 225 | + ) -> AsyncArray[ArrayV2Metadata]:... |
| 226 | + |
| 227 | + @overload |
| 228 | + @classmethod |
| 229 | + async def create( |
| 230 | + cls, |
| 231 | + store: StoreLike, |
| 232 | + *, |
| 233 | + # v2 and v3 |
| 234 | + shape: ShapeLike, |
| 235 | + dtype: npt.DTypeLike, |
| 236 | + zarr_format: Literal[3], |
| 237 | + fill_value: Any | None = None, |
| 238 | + attributes: dict[str, JSON] | None = None, |
| 239 | + # v3 only |
| 240 | + chunk_shape: ChunkCoords | None = None, |
| 241 | + chunk_key_encoding: ( |
| 242 | + ChunkKeyEncoding |
| 243 | + | tuple[Literal["default"], Literal[".", "/"]] |
| 244 | + | tuple[Literal["v2"], Literal[".", "/"]] |
| 245 | + | None |
| 246 | + ) = None, |
| 247 | + codecs: Iterable[Codec | dict[str, JSON]] | None = None, |
| 248 | + dimension_names: Iterable[str] | None = None, |
| 249 | + # v2 only |
| 250 | + chunks: ShapeLike | None = None, |
| 251 | + dimension_separator: Literal[".", "/"] | None = None, |
| 252 | + order: Literal["C", "F"] | None = None, |
| 253 | + filters: list[dict[str, JSON]] | None = None, |
| 254 | + compressor: dict[str, JSON] | None = None, |
| 255 | + # runtime |
| 256 | + exists_ok: bool = False, |
| 257 | + data: npt.ArrayLike | None = None, |
| 258 | + ) -> AsyncArray[ArrayV3Metadata]:... |
| 259 | + |
194 | 260 | @classmethod |
195 | 261 | async def create( |
196 | 262 | cls, |
@@ -347,9 +413,7 @@ async def _create_v3( |
347 | 413 |
|
348 | 414 | array = cls(metadata=metadata, store_path=store_path) |
349 | 415 | await array._save_metadata(metadata, ensure_parents=True) |
350 | | - # type inference is inconsistent here and seems to conclude |
351 | | - # that array has type Array[ArrayV2Metadata] |
352 | | - return array # type: ignore[return-value] |
| 416 | + return array |
353 | 417 |
|
354 | 418 | @classmethod |
355 | 419 | async def _create_v2( |
@@ -388,7 +452,7 @@ async def _create_v2( |
388 | 452 | ) |
389 | 453 | array = cls(metadata=metadata, store_path=store_path) |
390 | 454 | await array._save_metadata(metadata, ensure_parents=True) |
391 | | - return array # type: ignore[return-value] |
| 455 | + return array |
392 | 456 |
|
393 | 457 | @classmethod |
394 | 458 | def from_dict( |
@@ -500,7 +564,7 @@ def _iter_chunk_coords( |
500 | 564 | keyword is used, iteration will start at the chunk index specified by `origin`. |
501 | 565 | The default behavior is to start at the origin of the grid coordinate space. |
502 | 566 | If the `selection_shape` keyword is used, iteration will be bounded over a contiguous region |
503 | | - ranging from `[origin, origin + selection_shape]`, where the upper bound is exclusive as |
| 567 | + ranging from `[origin, origin selection_shape]`, where the upper bound is exclusive as |
504 | 568 | per python indexing conventions. |
505 | 569 |
|
506 | 570 | Parameters |
@@ -2314,10 +2378,10 @@ def resize(self, new_shape: ChunkCoords) -> Array: |
2314 | 2378 | the data falling outside the new array but inside the boundary chunks |
2315 | 2379 | would be restored by a subsequent resize operation that grows the array size. |
2316 | 2380 | """ |
2317 | | - return type(self)(sync(self._async_array.resize(new_shape))) # type: ignore[arg-type] |
| 2381 | + return type(self)(sync(self._async_array.resize(new_shape))) |
2318 | 2382 |
|
2319 | 2383 | def update_attributes(self, new_attributes: dict[str, JSON]) -> Array: |
2320 | | - return type(self)(sync(self._async_array.update_attributes(new_attributes))) # type: ignore[arg-type] |
| 2384 | + return type(self)(sync(self._async_array.update_attributes(new_attributes))) |
2321 | 2385 |
|
2322 | 2386 | def __repr__(self) -> str: |
2323 | 2387 | return f"<Array {self.store_path} shape={self.shape} dtype={self.dtype}>" |
|
0 commit comments