Fix idxmax/idxmin with IntervalIndex coordinates (GH#11300)#11408
Open
C1-BA-B1-F3 wants to merge 2 commits into
Open
Fix idxmax/idxmin with IntervalIndex coordinates (GH#11300)#11408C1-BA-B1-F3 wants to merge 2 commits into
C1-BA-B1-F3 wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using or on a DataArray with IntervalIndex coordinates, a is raised:
Root Cause
The issue has two parts:
appends to the key to force 0-d slices instead of scalars. This works for numpy arrays but not for wrapping .
is always 1-D and cannot represent scalar (0-d) data.
Fix
****: Strip trailing Ellipsis from the key since pandas extension arrays are 1-D and don't support this numpy convention.
****: 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