Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: IntervalIndex.unique() only contains the first interval if all interval borders are negative #61920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
khemkaran10 wants to merge 15 commits into pandas-dev:main
base: main
Choose a base branch
Loading
from khemkaran10:issue_61917

Conversation

Copy link
Contributor

@khemkaran10 khemkaran10 commented Jul 22, 2025

Fixes: #61917
Before FIx ❌:

idx_neg = pd.IntervalIndex.from_tuples([(-4, -3), (-4, -3), (-3, -2), (-3, -2), (-2, -1), (-2, -1)])
print(idx_neg.unique())
# Output:
# IntervalIndex([(-4, -3]], dtype='interval[int64, right]')

After Fix ✅:

idx_neg = pd.IntervalIndex.from_tuples([(-4, -3), (-4, -3), (-3, -2), (-3, -2), (-2, -1), (-2, -1)])
print(idx_neg.unique())
# output:
# IntervalIndex([(-4, -3], (-3, -2], (-2, -1]], dtype='interval[int64, right]')

@simonjayhawkins simonjayhawkins added Bug Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Interval Interval data type labels Jul 22, 2025
@simonjayhawkins simonjayhawkins changed the title (削除) FIX BUG: IntervalIndex.unique() only contains the first interval if all interval borders are negative (削除ここまで) (追記) BUG: IntervalIndex.unique() only contains the first interval if all interval borders are negative (追記ここまで) Jul 22, 2025
Copy link

il1sf4 commented Jul 31, 2025

Hello @khemkaran10, I have tried your fix and I have the following issue. When i run with this branch this code:
import pandas as pd idx_neg = pd.IntervalIndex.from_tuples([(-4, -3), (-4, -3), (-3, -2), (-3, -2), (-2, -1), (-2, -1)]) print(idx_neg.unique())
I get from the last line: E ValueError: left side of interval must be <= right side
I have tried to debug the problem and I found that:
unique() from interval.py calls at the return self._from_combined(nc). the _from_combined() method from interval.py sets nc to nc = combined.view("i8").reshape(-1, 2). Here is the problem, because:
array([[-4.-3.j],
[-3.-2.j],
[-2.-1.j]])
gets transformed to:
array([[-4607182418800017408, -4609434218613702656],
[-4609434218613702656, -4611686018427387904],
[-4611686018427387904, -4616189618054758400]])
and then the method delivers an invalid Intervalindex, where left side is greater then the right side.

Gould you try to run the code again and assure, that idx_neg.unique() really returns "IntervalIndex([(-4, -3], (-3, -2], (-2, -1]], dtype='interval[int64, right]')"? In my tests the return is "IntervalIndex([([-4607182418800017408, -4609434218613702656], (-4609434218613702656, -4611686018427387904], (-4611686018427387904, -4616189618054758400]], dtype='interval[int64, right]')" which triggers the error: "E ValueError: left side of interval must be <= right side"

khemkaran10 reacted with thumbs up emoji

Copy link
Contributor Author

@il1sf4 Thanks for pointing out. I have update the PR.

il1sf4 reacted with thumbs up emoji

)._from_sequence(nc[:, 1], dtype=dtype)
else:
assert isinstance(dtype, np.dtype)
nc = np.hstack(
Copy link
Member

@jbrockmendel jbrockmendel Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the hstack really necessary here since the next 2 lines is just splitting them back up?

Copy link
Contributor Author

@khemkaran10 khemkaran10 Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @jbrockmendel , It's not required. I'll change this.

Copy link
Contributor

github-actions bot commented Sep 1, 2025

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

Copy link

@il1sf4 il1sf4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue is fixed, approved.

Copy link

il1sf4 commented Sep 1, 2025

Dear reviewers @jbrockmendel , @mroeschke , please, check again the bugfix commits and if you have no other findings, please, approve the PR. I need this patch to be released ASAP for my project.

Copy link

il1sf4 commented Sep 16, 2025

Why is taking so long this bugfix PR to be merged?

Copy link
Contributor

@mroeschke is there anything blocking this? This fix is needed here. Anything that we can do to get this merged?

Copy link
Contributor

@khemkaran10 are the last two comments by @jbrockmendel resolved?

khemkaran10 reacted with thumbs up emoji

Copy link
Contributor Author

@johannes-mueller yes both are resolved.

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gentle ping @jbrockmendel

Copy link
Contributor Author

@rhshadrach @jbrockmendel I have made the requested changes. I think it's good to merge now.

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

@jbrockmendel jbrockmendel jbrockmendel left review comments

@mroeschke mroeschke mroeschke left review comments

@rhshadrach rhshadrach rhshadrach requested changes

+1 more reviewer

@il1sf4 il1sf4 il1sf4 approved these changes

Reviewers whose approvals may not affect merge requirements

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Interval Interval data type Stale
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

BUG: IntervalIndex.unique() only contains the first interval if all interval borders are negative

AltStyle によって変換されたページ (->オリジナル) /