Fix mypy errors with numpy 2.3 type stubs #10792
Merged
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.
Summary
Fixes the mypy test failures reported in #10791. The issue was caused by numpy 2.3's stricter type stubs revealing legitimate type issues in our codebase.
The Problem
CI environments use numpy 2.3.3 (via conda-forge) while local development was constrained to numpy<2.3 due to an outdated numba compatibility constraint. NumPy 2.3 has stricter type annotations that caught several type issues:
xarray/core/indexing.py: Lists were being used to hold mixed types (slices and ndarrays) without proper type annotationsChanges
Updated dependency constraints:
numpy<2.3constraintnumba>=0.62(numba 0.62+ supports numpy 2.3)Fixed type annotations:
backend_indexer_elemsandnp_indexer_elemsinindexing.pyslice | np.ndarraytypes for use withOuterIndexerandVectorizedIndexerAdded targeted type ignores:
test_namedarray.py: MaskedArray not in duckarray uniontest_parallelcompat.py: Covariant return type in compute method overridetest_dataarray.pyto handle union type for mask attributeTesting
Closes #10791
🤖 Generated with Claude Code