1616if TYPE_CHECKING :
1717 from numpy .typing import NDArray
1818
19- from ..compat import Index , Index1D , Index1DNorm
19+ from ..typing import Index , Index1D , _Index1DNorm
2020
2121
2222def _normalize_indices (
2323 index : Index | None , names0 : pd .Index , names1 : pd .Index
24- ) -> tuple [Index1DNorm | int | np .integer , Index1DNorm | int | np .integer ]:
24+ ) -> tuple [_Index1DNorm | int | np .integer , _Index1DNorm | int | np .integer ]:
2525 # deal with tuples of length 1
2626 if isinstance (index , tuple ) and len (index ) == 1 :
2727 index = index [0 ]
@@ -33,7 +33,7 @@ def _normalize_indices(
3333
3434def _normalize_index ( # noqa: PLR0911, PLR0912
3535 indexer : Index1D , index : pd .Index
36- ) -> Index1DNorm | int | np .integer :
36+ ) -> _Index1DNorm | int | np .integer :
3737 # TODO: why is this here? All tests pass without it and it seems at the minimum not strict enough.
3838 if not isinstance (index , pd .RangeIndex ) and index .dtype in (np .float64 , np .int64 ):
3939 msg = f"Don’t call _normalize_index with non-categorical/string names and non-range index { index } "
@@ -172,7 +172,7 @@ def unpack_index(index: Index) -> tuple[Index1D, Index1D]:
172172@singledispatch
173173def _subset (
174174 a : np .ndarray | pd .DataFrame ,
175- subset_idx : tuple [Index1DNorm ] | tuple [Index1DNorm , Index1DNorm ],
175+ subset_idx : tuple [_Index1DNorm ] | tuple [_Index1DNorm , _Index1DNorm ],
176176):
177177 # Select as combination of indexes, not coordinates
178178 # Correcting for indexing behaviour of np.ndarray
@@ -183,7 +183,7 @@ def _subset(
183183
184184@_subset .register (DaskArray )
185185def _subset_dask (
186- a : DaskArray , subset_idx : tuple [Index1DNorm ] | tuple [Index1DNorm , Index1DNorm ]
186+ a : DaskArray , subset_idx : tuple [_Index1DNorm ] | tuple [_Index1DNorm , _Index1DNorm ]
187187):
188188 if len (subset_idx ) > 1 and all (isinstance (x , Iterable ) for x in subset_idx ):
189189 if issparse (a ._meta ) and a ._meta .format == "csc" :
@@ -196,7 +196,7 @@ def _subset_dask(
196196@_subset .register (CSArray )
197197def _subset_sparse (
198198 a : CSMatrix | CSArray ,
199- subset_idx : tuple [Index1DNorm ] | tuple [Index1DNorm , Index1DNorm ],
199+ subset_idx : tuple [_Index1DNorm ] | tuple [_Index1DNorm , _Index1DNorm ],
200200):
201201 # Correcting for indexing behaviour of sparse.spmatrix
202202 if len (subset_idx ) > 1 and all (isinstance (x , Iterable ) for x in subset_idx ):
@@ -211,14 +211,14 @@ def _subset_sparse(
211211@_subset .register (Dataset2D )
212212def _subset_df (
213213 df : pd .DataFrame | Dataset2D ,
214- subset_idx : tuple [Index1DNorm ] | tuple [Index1DNorm , Index1DNorm ],
214+ subset_idx : tuple [_Index1DNorm ] | tuple [_Index1DNorm , _Index1DNorm ],
215215):
216216 return df .iloc [subset_idx ]
217217
218218
219219@_subset .register (AwkArray )
220220def _subset_awkarray (
221- a : AwkArray , subset_idx : tuple [Index1DNorm ] | tuple [Index1DNorm , Index1DNorm ]
221+ a : AwkArray , subset_idx : tuple [_Index1DNorm ] | tuple [_Index1DNorm , _Index1DNorm ]
222222):
223223 if all (isinstance (x , Iterable ) for x in subset_idx ):
224224 subset_idx = np .ix_ (* subset_idx )
@@ -228,7 +228,7 @@ def _subset_awkarray(
228228# Registration for SparseDataset occurs in sparse_dataset.py
229229@_subset .register (h5py .Dataset )
230230def _subset_dataset (
231- d : h5py .Dataset , subset_idx : tuple [Index1DNorm ] | tuple [Index1DNorm , Index1DNorm ]
231+ d : h5py .Dataset , subset_idx : tuple [_Index1DNorm ] | tuple [_Index1DNorm , _Index1DNorm ]
232232):
233233 order : tuple [NDArray [np .integer ] | slice , ...]
234234 inv_order : tuple [NDArray [np .integer ] | slice , ...]
@@ -252,8 +252,8 @@ def _index_order_and_inverse(
252252@overload
253253def _index_order_and_inverse (axis_idx : slice ) -> tuple [slice , slice ]: ...
254254def _index_order_and_inverse (
255- axis_idx : Index1DNorm ,
256- ) -> tuple [Index1DNorm , NDArray [np .integer ] | slice ]:
255+ axis_idx : _Index1DNorm ,
256+ ) -> tuple [_Index1DNorm , NDArray [np .integer ] | slice ]:
257257 """Order and get inverse index array."""
258258 if not isinstance (axis_idx , np .ndarray ):
259259 return axis_idx , slice (None )
@@ -270,8 +270,8 @@ def _process_index_for_h5py(
270270@overload
271271def _process_index_for_h5py (idx : slice ) -> tuple [slice , None ]: ...
272272def _process_index_for_h5py (
273- idx : Index1DNorm ,
274- ) -> tuple [Index1DNorm , NDArray [np .integer ] | None ]:
273+ idx : _Index1DNorm ,
274+ ) -> tuple [_Index1DNorm , NDArray [np .integer ] | None ]:
275275 """Process a single index for h5py compatibility, handling sorting and duplicates."""
276276 if not isinstance (idx , np .ndarray ):
277277 # Not an array (slice, integer, list) - no special processing needed
@@ -294,7 +294,7 @@ def _process_index_for_h5py(
294294
295295def _safe_fancy_index_h5py (
296296 dataset : h5py .Dataset ,
297- subset_idx : tuple [Index1DNorm ] | tuple [Index1DNorm , Index1DNorm ],
297+ subset_idx : tuple [_Index1DNorm ] | tuple [_Index1DNorm , _Index1DNorm ],
298298) -> h5py .Dataset :
299299 # Handle multi-dimensional indexing of h5py dataset
300300 # This avoids h5py's limitation with multi-dimensional fancy indexing
@@ -331,7 +331,7 @@ def _safe_fancy_index_h5py(
331331 return result
332332
333333
334- def _get_index_size (idx : Index1DNorm , dim_size : int ) -> int :
334+ def _get_index_size (idx : _Index1DNorm , dim_size : int ) -> int :
335335 """Get size for any index type."""
336336 if isinstance (idx , slice ):
337337 return len (range (* idx .indices (dim_size )))
0 commit comments