Skip to content

Fix scalar selection for nested tuple MultiIndex keys - #11348

Merged
dcherian merged 3 commits into
pydata:mainfrom
puneetdixit200:fix-nested-tuple-multiindex-scalar-sel
Aug 19, 2026
Merged

Fix scalar selection for nested tuple MultiIndex keys#11348
dcherian merged 3 commits into
pydata:mainfrom
puneetdixit200:fix-nested-tuple-multiindex-scalar-sel

Conversation

@puneetdixit200

Copy link
Copy Markdown
Contributor

Description

Closes #11341.

Full-length MultiIndex tuple labels now try exact key lookup before falling back to pandas' nested get_locs selector path. This lets tuple-valued MultiIndex levels behave as scalar keys when the full key identifies a single row, while preserving the existing fallback for nested selectors.

Tests run:

  • .venv\Scripts\python -m pytest xarray\tests\test_dataarray.py::TestDataArray::test_selection_multiindex xarray\tests\test_dataarray.py::TestDataArray::test_selection_multiindex_nested_tuple_level_value xarray\tests\test_dataarray.py::TestDataArray::test_selection_multiindex_remove_unused xarray\tests\test_indexes.py::TestPandasMultiIndex::test_sel -q
  • .venv\Scripts\python -m pytest xarray\tests\test_indexes.py::TestPandasMultiIndex -q
  • .venv\Scripts\python -m pytest xarray\tests\test_dataarray.py -q -k multiindex
  • .venv\Scripts\python -m ruff format --check xarray\core\indexes.py xarray\tests\test_dataarray.py
  • .venv\Scripts\python -m ruff check xarray\core\indexes.py xarray\tests\test_dataarray.py
  • git diff --check

Checklist

AI Disclosure

  • This PR contains AI-assisted content.
    • I have tested any AI-assisted content in my PR.
    • I take responsibility for any AI-assisted content in my PR.
      Tools: OpenAI language model assistance.

@puneetdixit200
puneetdixit200 force-pushed the fix-nested-tuple-multiindex-scalar-sel branch from 76a8b45 to b78ab50 Compare May 30, 2026 10:58
@dcherian dcherian added the plan to merge Final call for comments label Jun 24, 2026
@dcherian
dcherian merged commit 0e627d9 into pydata:main Aug 19, 2026
43 of 44 checks passed
@welcome

welcome Bot commented Aug 19, 2026

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

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

Labels

plan to merge Final call for comments topic-hypothesis Strategies or tests using the hypothesis library topic-indexing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A single nested tuple MultiIndex key is located correctly but preserves the dimension

2 participants