From e196bc50f1955527ae2c742a5faa3992f01caee8 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Mon, 20 Jul 2026 15:47:44 +0200 Subject: [PATCH] fix(typing): fix mypy errors in indexing with numpy 2.5.1 stubs numpy 2.5.1's type stubs infer a float64 array for np.asarray on a narrowed list/int, breaking the declared selection types in replace_lists and CoordinateIndexer.__init__. Cast the asarray result in replace_lists (a plain list may hold ints or bools, so the stubs cannot infer ArrayOfIntOrBool), and pass dtype=np.intp explicitly in CoordinateIndexer, which also makes the runtime dtype deterministic. Assisted-by: ClaudeCode:claude-fable-5 --- src/zarr/core/indexing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/zarr/core/indexing.py b/src/zarr/core/indexing.py index f6eb495cd9..49f50f37b3 100644 --- a/src/zarr/core/indexing.py +++ b/src/zarr/core/indexing.py @@ -511,7 +511,8 @@ def replace_ellipsis(selection: Any, shape: tuple[int, ...]) -> SelectionNormali def replace_lists(selection: SelectionNormalized) -> SelectionNormalized: return tuple( - np.asarray(dim_sel) if isinstance(dim_sel, list) else dim_sel for dim_sel in selection + cast("ArrayOfIntOrBool", np.asarray(dim_sel)) if isinstance(dim_sel, list) else dim_sel + for dim_sel in selection ) @@ -1192,7 +1193,7 @@ def __init__( # some initial normalization selection_normalized = cast("CoordinateSelectionNormalized", ensure_tuple(selection)) selection_normalized = tuple( - np.asarray([i]) if is_integer(i) else i for i in selection_normalized + np.asarray([i], dtype=np.intp) if is_integer(i) else i for i in selection_normalized ) selection_normalized = cast( "CoordinateSelectionNormalized", replace_lists(selection_normalized)