fix(typing): fix mypy errors in indexing with numpy 2.5.1 stubs#231
Open
d-v-b wants to merge 1 commit into
Open
fix(typing): fix mypy errors in indexing with numpy 2.5.1 stubs#231d-v-b wants to merge 1 commit into
d-v-b wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Fixes the two mypy errors reported on zarr-developers#4151 (the dependabot bump of numpy 2.5.0 → 2.5.1 and mypy 2.1.0 → 2.2.0), both in
src/zarr/core/indexing.py:replace_lists(line 514): numpy 2.5.1's stubs inferndarray[..., float64]fornp.asarray(dim_sel)on a narrowedlist. A plainlistmay hold ints or bools, so the stubs cannot inferArrayOfIntOrBool; the result is nowcastto that alias, matching the existing cast style in the file.CoordinateIndexer.__init__(line 1195):np.asarray([i])on anis_integer-narrowedilikewise infers float64. Passingdtype=np.intpexplicitly satisfiesCoordinateSelectionNormalizedand makes the runtime dtype deterministic across platforms as a bonus.Verified locally:
uv run mypy src testsclean with the current lock (numpy 2.5.0) and with numpy upgraded to 2.5.1uv run pytest tests/test_indexing.py: 427 passed, 1 skipped, 2 xfailed🤖 Generated with Claude Code