44import numbers
55
66import numpy as np
7+ import numpy .typing as npt
78
89
910from zarr .errors import (
@@ -330,6 +331,7 @@ def __init__(self, selection, array):
330331 # setup per-dimension indexers
331332 dim_indexers = []
332333 for dim_sel , dim_len , dim_chunk_len in zip (selection , array ._shape , array ._chunks ):
334+ dim_indexer : IntDimIndexer | SliceDimIndexer
333335 if is_integer (dim_sel ):
334336 dim_indexer = IntDimIndexer (dim_sel , dim_len , dim_chunk_len )
335337
@@ -521,9 +523,12 @@ def __iter__(self):
521523 else :
522524 start = self .chunk_nitems_cumsum [dim_chunk_ix - 1 ]
523525 stop = self .chunk_nitems_cumsum [dim_chunk_ix ]
526+
527+ dim_out_sel : slice | np .ndarray
524528 if self .order == Order .INCREASING :
525529 dim_out_sel = slice (start , stop )
526530 else :
531+ assert self .dim_out_sel is not None
527532 dim_out_sel = self .dim_out_sel [start :stop ]
528533
529534 # find region in chunk
@@ -577,11 +582,10 @@ def oindex_set(a, selection, value):
577582 selection = ix_ (selection , a .shape )
578583 if not np .isscalar (value ) and drop_axes :
579584 value = np .asanyarray (value )
580- value_selection = [slice (None )] * len (a .shape )
585+ value_selection : list [ slice | None ] = [slice (None )] * len (a .shape )
581586 for i in drop_axes :
582587 value_selection [i ] = np .newaxis
583- value_selection = tuple (value_selection )
584- value = value [value_selection ]
588+ value = value [tuple (value_selection )]
585589 a [selection ] = value
586590
587591
@@ -597,6 +601,7 @@ def __init__(self, selection, array):
597601 # setup per-dimension indexers
598602 dim_indexers = []
599603 for dim_sel , dim_len , dim_chunk_len in zip (selection , array ._shape , array ._chunks ):
604+ dim_indexer : IntDimIndexer | SliceDimIndexer | IntArrayDimIndexer | BoolArrayDimIndexer
600605 if is_integer (dim_sel ):
601606 dim_indexer = IntDimIndexer (dim_sel , dim_len , dim_chunk_len )
602607
@@ -622,6 +627,8 @@ def __init__(self, selection, array):
622627 self .dim_indexers = dim_indexers
623628 self .shape = tuple (s .nitems for s in self .dim_indexers if not isinstance (s , IntDimIndexer ))
624629 self .is_advanced = not is_basic_selection (selection )
630+
631+ self .drop_axes : tuple [int , ...] | None
625632 if self .is_advanced :
626633 self .drop_axes = tuple (
627634 i
@@ -797,6 +804,7 @@ def __init__(self, selection, array):
797804 boundscheck_indices (dim_sel , dim_len )
798805
799806 # compute chunk index for each point in the selection
807+ chunks_multi_index : npt .ArrayLike
800808 chunks_multi_index = tuple (
801809 dim_sel // dim_chunk_len for (dim_sel , dim_chunk_len ) in zip (selection , array ._chunks )
802810 )
@@ -848,6 +856,8 @@ def __iter__(self):
848856 else :
849857 start = self .chunk_nitems_cumsum [chunk_rix - 1 ]
850858 stop = self .chunk_nitems_cumsum [chunk_rix ]
859+
860+ out_selection : slice | np .ndarray
851861 if self .sel_sort is None :
852862 out_selection = slice (start , stop )
853863 else :
@@ -952,6 +962,7 @@ def check_no_multi_fields(fields):
952962
953963
954964def pop_fields (selection ):
965+ fields : str | None | list [str ]
955966 if isinstance (selection , str ):
956967 # single field selection
957968 fields = selection
0 commit comments