Skip to content

Fix idxmax on DataArray with IntervalIndex coordinates#11301

Open
j-haacker wants to merge 2 commits intopydata:mainfrom
j-haacker:fix/intervalindex_idxmax
Open

Fix idxmax on DataArray with IntervalIndex coordinates#11301
j-haacker wants to merge 2 commits intopydata:mainfrom
j-haacker:fix/intervalindex_idxmax

Conversation

@j-haacker
Copy link
Copy Markdown
Contributor

@j-haacker j-haacker commented Apr 16, 2026

Description

Fixes a regression in DataArray.idxmax() for pandas.IntervalIndex coordinates.

On current main, a simple IntervalIndex-backed DataArray.idxmax() call raises TypeError: len() of unsized object while older xarray releases (verified for 2024.11) returned the selected interval label correctly. The failure comes from _calc_idxminmax() rebuilding the coordinate result through the generic variable indexing path, which breaks for extension-array-backed interval coordinates.

This PR adds a minimal regression test and applies a narrow fix in _calc_idxminmax(): for extension-array-backed coordinates, it reconstructs the selected labels directly instead of routing through the broken replacement path. This restores the expected idxmax() behavior and also fixes the same underlying issue for idxmin().

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR. Tools: Codex

Co-authored-by: Claude <noreply@anthropic.com>
@welcome
Copy link
Copy Markdown

welcome bot commented Apr 16, 2026

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

@j-haacker
Copy link
Copy Markdown
Contributor Author

The failing CI shows "39 failed, 1 skipped, 2 warnings". To me the failing tests seem unrelated to the changes. Below one of the 39 similar fails.
FAILED xarray/tests/test_dataarray_typing.yml::test_mypy_pipe_lambda_noarg_return_type - AttributeError: 'FilesystemMetadataStore' object has no attribute 'close'

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.idxmax() fails if coordinates are intervals

1 participant