Skip to content

Commit 3de5e6a

Browse files
committed
fix: satisfy numpy 2.5.1 type stubs in indexing selection normalization
numpy 2.5.1 stubs infer np.asarray(<list>) as a float64 array, so mypy now rejects the untyped asarray calls in replace_lists and CoordinateIndexer. Pass dtype=np.intp where the integer dtype is guaranteed, and cast to ArrayOfIntOrBool where the list contents are only known at runtime. Assisted-by: ClaudeCode:claude-fable-5
1 parent 2e02dab commit 3de5e6a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎src/zarr/core/indexing.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ def replace_ellipsis(selection: Any, shape: tuple[int, ...]) -> SelectionNormali
512512

513513
def replace_lists(selection: SelectionNormalized) -> SelectionNormalized:
514514
return tuple(
515-
np.asarray(dim_sel) if isinstance(dim_sel, list) else dim_sel for dim_sel in selection
515+
cast("ArrayOfIntOrBool", np.asarray(dim_sel)) if isinstance(dim_sel, list) else dim_sel
516+
for dim_sel in selection
516517
)
517518

518519

@@ -1193,7 +1194,7 @@ def __init__(
11931194
# some initial normalization
11941195
selection_normalized = cast("CoordinateSelectionNormalized", ensure_tuple(selection))
11951196
selection_normalized = tuple(
1196-
np.asarray([i]) if is_integer(i) else i for i in selection_normalized
1197+
np.asarray([i], dtype=np.intp) if is_integer(i) else i for i in selection_normalized
11971198
)
11981199
selection_normalized = cast(
11991200
"CoordinateSelectionNormalized", replace_lists(selection_normalized)

0 commit comments

Comments
 (0)