15
15
from typing import Any , Dict , Iterable , Literal , Optional , Tuple , Union
16
16
17
17
import numpy as np
18
+ import numpy .typing as npt
18
19
from zarr .abc .codec import Codec
19
20
20
21
@@ -76,7 +77,7 @@ async def create(
76
77
store : StoreLike ,
77
78
* ,
78
79
shape : ChunkCoords ,
79
- dtype : Union [ str , np . dtype ] ,
80
+ dtype : npt . DTypeLike ,
80
81
chunk_shape : ChunkCoords ,
81
82
fill_value : Optional [Any ] = None ,
82
83
chunk_key_encoding : Union [
@@ -175,14 +176,14 @@ def size(self) -> int:
175
176
return np .prod (self .metadata .shape ).item ()
176
177
177
178
@property
178
- def dtype (self ) -> np .dtype :
179
+ def dtype (self ) -> np .dtype [ Any ] :
179
180
return self .metadata .dtype
180
181
181
182
@property
182
- def attrs (self ) -> dict :
183
+ def attrs (self ) -> dict [ str , Any ] :
183
184
return self .metadata .attributes
184
185
185
- async def getitem (self , selection : Selection ) -> np . ndarray :
186
+ async def getitem (self , selection : Selection ) -> npt . NDArray [ Any ] :
186
187
assert isinstance (self .metadata .chunk_grid , RegularChunkGrid )
187
188
indexer = BasicIndexer (
188
189
selection ,
@@ -220,7 +221,7 @@ async def _read_chunk(
220
221
chunk_coords : ChunkCoords ,
221
222
chunk_selection : SliceSelection ,
222
223
out_selection : SliceSelection ,
223
- out : np . ndarray ,
224
+ out : npt . NDArray [ Any ] ,
224
225
) -> None :
225
226
chunk_spec = self .metadata .get_chunk_spec (chunk_coords , self .order )
226
227
chunk_key_encoding = self .metadata .chunk_key_encoding
@@ -242,7 +243,7 @@ async def _read_chunk(
242
243
else :
243
244
out [out_selection ] = self .metadata .fill_value
244
245
245
- async def setitem (self , selection : Selection , value : np . ndarray ) -> None :
246
+ async def setitem (self , selection : Selection , value : npt . NDArray [ Any ] ) -> None :
246
247
assert isinstance (self .metadata .chunk_grid , RegularChunkGrid )
247
248
chunk_shape = self .metadata .chunk_grid .chunk_shape
248
249
indexer = BasicIndexer (
@@ -282,7 +283,7 @@ async def setitem(self, selection: Selection, value: np.ndarray) -> None:
282
283
283
284
async def _write_chunk (
284
285
self ,
285
- value : np . ndarray ,
286
+ value : npt . NDArray [ Any ] ,
286
287
chunk_shape : ChunkCoords ,
287
288
chunk_coords : ChunkCoords ,
288
289
chunk_selection : SliceSelection ,
@@ -334,7 +335,7 @@ async def _write_chunk(
334
335
await self ._write_chunk_to_store (store_path , chunk_array , chunk_spec )
335
336
336
337
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
338
339
) -> None :
339
340
if np .all (chunk_array == self .metadata .fill_value ):
340
341
# chunks that only contain fill_value will be removed
@@ -402,7 +403,7 @@ def create(
402
403
store : StoreLike ,
403
404
* ,
404
405
shape : ChunkCoords ,
405
- dtype : Union [ str , np . dtype ] ,
406
+ dtype : npt . DTypeLike ,
406
407
chunk_shape : ChunkCoords ,
407
408
fill_value : Optional [Any ] = None ,
408
409
chunk_key_encoding : Union [
@@ -470,11 +471,11 @@ def size(self) -> int:
470
471
return self ._async_array .size
471
472
472
473
@property
473
- def dtype (self ) -> np .dtype :
474
+ def dtype (self ) -> np .dtype [ Any ] :
474
475
return self ._async_array .dtype
475
476
476
477
@property
477
- def attrs (self ) -> dict :
478
+ def attrs (self ) -> dict [ str , Any ] :
478
479
return self ._async_array .attrs
479
480
480
481
@property
@@ -489,12 +490,12 @@ def store_path(self) -> StorePath:
489
490
def order (self ) -> Literal ["C" , "F" ]:
490
491
return self ._async_array .order
491
492
492
- def __getitem__ (self , selection : Selection ) -> np . ndarray :
493
+ def __getitem__ (self , selection : Selection ) -> npt . NDArray [ Any ] :
493
494
return sync (
494
495
self ._async_array .getitem (selection ),
495
496
)
496
497
497
- def __setitem__ (self , selection : Selection , value : np . ndarray ) -> None :
498
+ def __setitem__ (self , selection : Selection , value : npt . NDArray [ Any ] ) -> None :
498
499
sync (
499
500
self ._async_array .setitem (selection , value ),
500
501
)
0 commit comments