Skip to content

Conversation

@max-sixty
Copy link
Collaborator

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:

  1. In xarray/core/indexing.py: Lists were being used to hold mixed types (slices and ndarrays) without proper type annotations
  2. In test files: Various type compatibility issues with MaskedArray, method overrides, and union types

Changes

  1. Updated dependency constraints:

    • Removed numpy<2.3 constraint
    • Updated numba>=0.62 (numba 0.62+ supports numpy 2.3)
  2. Fixed type annotations:

    • Added proper type hints for backend_indexer_elems and np_indexer_elems in indexing.py
    • These lists hold slice | np.ndarray types for use with OuterIndexer and VectorizedIndexer
  3. Added targeted type ignores:

    • test_namedarray.py: MaskedArray not in duckarray union
    • test_parallelcompat.py: Covariant return type in compute method override
    • Fixed assertion in test_dataarray.py to handle union type for mask attribute

Testing

  • ✅ All mypy checks pass
  • ✅ All affected tests pass
  • ✅ Pre-commit hooks pass

Closes #10791

🤖 Generated with Claude Code

NumPy 2.3 has stricter type annotations that revealed legitimate type
issues in our codebase. This commit:

1. Updates numpy constraint: removes numpy<2.3 and updates numba>=0.62
   since numba 0.62+ supports numpy 2.3
2. Fixes type annotations in indexing.py for lists that hold mixed types
3. Adds appropriate type ignores for known limitations

Fixes pydata#10791

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
These are needed in CI but marked unused locally - using both ignore codes
to satisfy both environments.
@max-sixty max-sixty merged commit d2ba1fe into pydata:main Sep 26, 2025
36 checks passed
@max-sixty max-sixty deleted the mypy branch September 26, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mypy tests failure in CI

1 participant