Skip to content

Conversation

@max-sixty
Copy link
Collaborator

Summary

  • Fix 26 mypy errors that appear with pandas-stubs 2.3.3.251219, which adds stricter type checking for pandas Index methods
  • All type: ignore comments include explanatory notes documenting why the stubs are stricter than actual pandas behavior
  • No runtime behavior changes

Changes

Added type: ignore with explanations for:

  • CFTimeIndex.__add__/__radd__ - return Self instead of pandas overloaded types
  • Index.get_indexer - accepts ndarray/list, not just Index
  • CategoricalIndex.remove_unused_categories - missing from stubs
  • Series.where - accepts broader argument types than stubs allow
  • ExtensionArray.astype - accepts ExtensionDtype
  • Series[datetime].__setitem__ - accepts np.nan (converts to NaT)
  • MultiIndex.rename - accepts list of names

Added explicit type annotations:

  • coordinates.py: codes as list[np.ndarray]
  • dataset.py: arrays and extension_arrays list types
  • indexes.py: new xr_index variable with PandasIndex | PandasMultiIndex type

Cleanup:

  • Removed unnecessary cast in remove_unused_levels_categories
  • Converted dict_keys to list for reorder_levels
  • Fixed test_backends.py variable naming (tdftdf_series)

Test plan

  • uv run dmypy run passes with 0 errors
  • pre-commit run --all-files passes
  • uv run pytest xarray -n auto - all tests pass

🤖 Generated with Claude Code

Remove the pandas-stubs version pin (<=2.2.3.241126) and fix the mypy
errors that appear with newer versions. This resolves pydata#10110.

Changes by category:

1. Added type: ignore comments with explanatory notes for cases where
   pandas-stubs is stricter than actual pandas behavior:
   - CFTimeIndex.__add__/__radd__ return Self instead of overloaded types
   - Index.get_indexer accepts ndarray/list, not just Index
   - CategoricalIndex.remove_unused_categories missing from stubs
   - Series.where accepts broader argument types
   - ExtensionArray.astype accepts ExtensionDtype
   - Series[datetime].__setitem__ accepts np.nan (converts to NaT)
   - MultiIndex.rename accepts list of names

2. Added explicit type annotations to help mypy infer correct types:
   - coordinates.py: codes as list[np.ndarray]
   - dataset.py: arrays and extension_arrays list types
   - indexes.py: xr_index variable with PandasIndex | PandasMultiIndex

3. Removed redundant casts and fixed variable shadowing:
   - Removed unnecessary cast in remove_unused_levels_categories
   - Converted dict_keys to list for reorder_levels
   - Fixed test_backends.py variable naming (tdf -> tdf_series)

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

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty
Copy link
Collaborator Author

fixes #10110

@max-sixty max-sixty added the plan to merge Final call for comments label Jan 1, 2026
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.

1 participant