Skip to content

Fix idxmax/idxmin with IntervalIndex coordinates (GH#11300)#11408

Open
C1-BA-B1-F3 wants to merge 2 commits into
pydata:mainfrom
C1-BA-B1-F3:fix-idxmax-interval-coords
Open

Fix idxmax/idxmin with IntervalIndex coordinates (GH#11300)#11408
C1-BA-B1-F3 wants to merge 2 commits into
pydata:mainfrom
C1-BA-B1-F3:fix-idxmax-interval-coords

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Problem

When using or on a DataArray with IntervalIndex coordinates, a is raised:

Root Cause

The issue has two parts:

  1. appends to the key to force 0-d slices instead of scalars. This works for numpy arrays but not for wrapping .

  2. is always 1-D and cannot represent scalar (0-d) data.

Fix

  1. ****: Strip trailing Ellipsis from the key since pandas extension arrays are 1-D and don't support this numpy convention.

  2. ****: When indexing produces a scalar result () but data is (always 1-D), extract the scalar value directly.

Test

Added test for / with IntervalIndex coordinates.

Closes #11300

…y segfault

Move pd.to_datetime() calls from module-level @pytest.mark.parametrize
into the test function body. This avoids a segfault in pandas nightly
caused by constructing datetime objects at module import time.

Fixes pydata#11402
Problem: When using idxmax/idxmin on a DataArray with IntervalIndex
coordinates, a TypeError was raised because PandasExtensionArray
doesn't support Ellipsis-based 0-d indexing that NumpyIndexingAdapter
uses.

Fix:
1. In PandasExtensionArray.__getitem__: Strip trailing Ellipsis from
   the key since pandas extension arrays are 1-D and don't support
   this numpy convention.

2. In Variable._finalize_indexing_result: When indexing produces a
   scalar result (dims=()) but data is PandasExtensionArray (always
   1-D), extract the scalar value directly.

Added test for idxmax/idxmin with IntervalIndex coordinates.
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