Skip to content

Commit f632771

Browse files
dstansbyjhamman
andauthored
Disallow any generics in zarr.array (#1861)
Co-authored-by: Joe Hamman <[email protected]>
1 parent 5bb3375 commit f632771

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ module = [
186186
"zarr.codecs.sharding",
187187
"zarr.codecs.transpose",
188188
"zarr.array_v2",
189-
"zarr.array",
190-
"zarr.sync",
191189
]
192190
disallow_any_generics = false
193191

src/zarr/array.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import Any, Dict, Iterable, Literal, Optional, Tuple, Union
1616

1717
import numpy as np
18+
import numpy.typing as npt
1819
from zarr.abc.codec import Codec
1920

2021

@@ -76,7 +77,7 @@ async def create(
7677
store: StoreLike,
7778
*,
7879
shape: ChunkCoords,
79-
dtype: Union[str, np.dtype],
80+
dtype: npt.DTypeLike,
8081
chunk_shape: ChunkCoords,
8182
fill_value: Optional[Any] = None,
8283
chunk_key_encoding: Union[
@@ -175,14 +176,14 @@ def size(self) -> int:
175176
return np.prod(self.metadata.shape).item()
176177

177178
@property
178-
def dtype(self) -> np.dtype:
179+
def dtype(self) -> np.dtype[Any]:
179180
return self.metadata.dtype
180181

181182
@property
182-
def attrs(self) -> dict:
183+
def attrs(self) -> dict[str, Any]:
183184
return self.metadata.attributes
184185

185-
async def getitem(self, selection: Selection) -> np.ndarray:
186+
async def getitem(self, selection: Selection) -> npt.NDArray[Any]:
186187
assert isinstance(self.metadata.chunk_grid, RegularChunkGrid)
187188
indexer = BasicIndexer(
188189
selection,
@@ -220,7 +221,7 @@ async def _read_chunk(
220221
chunk_coords: ChunkCoords,
221222
chunk_selection: SliceSelection,
222223
out_selection: SliceSelection,
223-
out: np.ndarray,
224+
out: npt.NDArray[Any],
224225
) -> None:
225226
chunk_spec = self.metadata.get_chunk_spec(chunk_coords, self.order)
226227
chunk_key_encoding = self.metadata.chunk_key_encoding
@@ -242,7 +243,7 @@ async def _read_chunk(
242243
else:
243244
out[out_selection] = self.metadata.fill_value
244245

245-
async def setitem(self, selection: Selection, value: np.ndarray) -> None:
246+
async def setitem(self, selection: Selection, value: npt.NDArray[Any]) -> None:
246247
assert isinstance(self.metadata.chunk_grid, RegularChunkGrid)
247248
chunk_shape = self.metadata.chunk_grid.chunk_shape
248249
indexer = BasicIndexer(
@@ -282,7 +283,7 @@ async def setitem(self, selection: Selection, value: np.ndarray) -> None:
282283

283284
async def _write_chunk(
284285
self,
285-
value: np.ndarray,
286+
value: npt.NDArray[Any],
286287
chunk_shape: ChunkCoords,
287288
chunk_coords: ChunkCoords,
288289
chunk_selection: SliceSelection,
@@ -334,7 +335,7 @@ async def _write_chunk(
334335
await self._write_chunk_to_store(store_path, chunk_array, chunk_spec)
335336

336337
async def _write_chunk_to_store(
337-
self, store_path: StorePath, chunk_array: np.ndarray, chunk_spec: ArraySpec
338+
self, store_path: StorePath, chunk_array: npt.NDArray[Any], chunk_spec: ArraySpec
338339
) -> None:
339340
if np.all(chunk_array == self.metadata.fill_value):
340341
# chunks that only contain fill_value will be removed
@@ -402,7 +403,7 @@ def create(
402403
store: StoreLike,
403404
*,
404405
shape: ChunkCoords,
405-
dtype: Union[str, np.dtype],
406+
dtype: npt.DTypeLike,
406407
chunk_shape: ChunkCoords,
407408
fill_value: Optional[Any] = None,
408409
chunk_key_encoding: Union[
@@ -470,11 +471,11 @@ def size(self) -> int:
470471
return self._async_array.size
471472

472473
@property
473-
def dtype(self) -> np.dtype:
474+
def dtype(self) -> np.dtype[Any]:
474475
return self._async_array.dtype
475476

476477
@property
477-
def attrs(self) -> dict:
478+
def attrs(self) -> dict[str, Any]:
478479
return self._async_array.attrs
479480

480481
@property
@@ -489,12 +490,12 @@ def store_path(self) -> StorePath:
489490
def order(self) -> Literal["C", "F"]:
490491
return self._async_array.order
491492

492-
def __getitem__(self, selection: Selection) -> np.ndarray:
493+
def __getitem__(self, selection: Selection) -> npt.NDArray[Any]:
493494
return sync(
494495
self._async_array.getitem(selection),
495496
)
496497

497-
def __setitem__(self, selection: Selection, value: np.ndarray) -> None:
498+
def __setitem__(self, selection: Selection, value: npt.NDArray[Any]) -> None:
498499
sync(
499500
self._async_array.setitem(selection, value),
500501
)

0 commit comments

Comments
 (0)