Skip to content

Fix scalar selection for nested tuple MultiIndex keys#11348

Open
puneetdixit200 wants to merge 5 commits into
pydata:mainfrom
puneetdixit200:fix-nested-tuple-multiindex-scalar-sel
Open

Fix scalar selection for nested tuple MultiIndex keys#11348
puneetdixit200 wants to merge 5 commits into
pydata:mainfrom
puneetdixit200:fix-nested-tuple-multiindex-scalar-sel

Conversation

@puneetdixit200
Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the topic-hypothesis Strategies or tests using the hypothesis library label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

1 participant