Skip to content

Mypy failures with MultiIndex #10110

Closed
Closed

Description

@jsignell

What is your issue?

As seen in https://github.com/pydata/xarray/actions/runs/13771308824/job/38510332904?pr=10109 and https://github.com/pydata/xarray/actions/runs/13771399760/job/38510636156?pr=10062

 xarray/core/indexes.py: note: In member "stack" of class "PandasMultiIndex":
xarray/core/indexes.py:1051: error: Argument 2 to "MultiIndex" has incompatible type "list[ndarray[Any, dtype[Any]]]"; expected "Sequence[Sequence[int]]"  [arg-type]
Generated Cobertura report: /home/runner/work/xarray/xarray/mypy_report/cobertura.xml
xarray/core/indexes.py: note: In member "from_variables_maybe_expand" of class "PandasMultiIndex":
xarray/core/indexes.py:1123: error: Argument 2 to "MultiIndex" has incompatible type "list[Iterable[int]]"; expected "Sequence[Sequence[int]]"  [arg-type]
xarray/core/coordinates.py: note: In member "to_index" of class "AbstractCoordinates":
xarray/core/coordinates.py:186: error: Argument 2 to "MultiIndex" has incompatible type "list[ndarray[Any, dtype[Any]]]"; expected "Sequence[Sequence[int]]"  [arg-type]
xarray/core/groupby.py: note: In member "factorize" of class "ComposedGrouper":
xarray/core/groupby.py:530: error: Argument 1 to "from_product" of "MultiIndex" has incompatible type "Generator[ndarray[Any, Any], None, None]"; expected "Sequence[Any]"  [arg-type]
xarray/tests/test_dataset.py: note: In member "test_drop_indexes" of class "TestDataset":
xarray/tests/test_dataset.py:2926: error: List item 0 has incompatible type "list[int]"; expected "tuple[Hashable, ...]"  [list-item]
xarray/tests/test_dataset.py:2926: error: List item 1 has incompatible type "list[int]"; expected "tuple[Hashable, ...]"  [list-item]
xarray/tests/test_dataset.py: note: In member "test_rename_multiindex" of class "TestDataset":
xarray/tests/test_dataset.py:3222: error: List item 0 has incompatible type "list[int]"; expected "tuple[Hashable, ...]"  [list-item]
xarray/tests/test_dataset.py:3222: error: List item 1 has incompatible type "list[int]"; expected "tuple[Hashable, ...]"  [list-item]
Installing missing stub packages:
/home/runner/micromamba/envs/xarray-tests/bin/python -m pip install types-openpyxl


Generated Cobertura report: /home/runner/work/xarray/xarray/mypy_report/cobertura.xml
Found 8 errors in 4 files (checked 177 source files)

Activity

  1. added
    needs triage
    on Mar 10, 2025
  2. benbovy commented on Mar 13, 2025

    @benbovy
    Member

    Thanks for the report @jsignell.

    The multiindex errors seem to result from pandas-dev/pandas-stubs#1126. I wonder if Sequence defined for some arguments of the MultiIndex constructors isn't too restrictive. This prevents using numpy arrays or iterables which we are using here and which seems valid (see also pandas-dev/pandas-stubs#1158).

  3. jsignell commented on Mar 13, 2025

    @jsignell
    MemberAuthor

    Yeah that makes sense. Maybe it makes sense to pin the stubs to get tests passing.

  4. removed
    needs triage
    on Mar 17, 2025
  5. added 4 commits that reference this issue on Jan 1, 2026
    93c6351
    28ffc54
    c344162
    c8f22a7
  6. added 2 commits that reference this issue on Jan 4, 2026
    a5caa3a
    db81f3a
  7. jsignell commented on Feb 25, 2026

    @jsignell
    MemberAuthor

    Closed by #11066 looks like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions