Skip to content

BUG: IntervalIndex.intersection returning duplicates #38834

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

Merged
merged 2 commits into from
Dec 31, 2020

Conversation

phofl
Copy link
Member

@phofl phofl commented Dec 30, 2020

Moved the wrong test code into a new test with adjusted behavior

@phofl phofl added Index Related to the Index class or subclasses Interval Interval data type labels Dec 30, 2020
@jreback jreback added this to the 1.3 milestone Dec 30, 2020
@jreback
Copy link
Contributor

jreback commented Dec 30, 2020

can you also add the exhaustive test from the op

def check_intersection_commutative(left, right):
    assert left.intersection(right).equals(right.intersection(left))

@pytest.mark.parametrize("index_maker", tm.index_subclass_makers_generator())
def test_intersection_uniqueness(index_maker):
    if index_make is tm.makeMultiIndex:
        pytest.pass()  # This index maker is bugged
    ind_unique = index_maker(k=5)
    ind_non_unique = idx_unique[[0, 0, 1, 2, 3, 4]]

    check_intersection_commutative(ind_unique, ind_non_unique)
    assert idx_unique.intersection(idx_non_unique).is_unique

except use the index fixture

@phofl
Copy link
Member Author

phofl commented Dec 30, 2020

Done, moved it into the regular setops file.

@jreback jreback merged commit cc9c9b9 into pandas-dev:master Dec 31, 2020
@jreback
Copy link
Contributor

jreback commented Dec 31, 2020

thanks @phofl

# No duplicates in empty indexes
return

def check_intersection_commutative(left, right):
Copy link
Member

Choose a reason for hiding this comment

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

ive been thinking we should make something like this of the form

@pytest.mark.parametrize("method", ["union", "intersection", "symmetric_difference"])
def test_setops_commute(method, index, index_fixture2):
    [...]

we've consolidated a lot of the behavior recently, but we still have some length-0 checks and self.equals(other) checks that seem a little wobbly

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that sounds reasonable

@phofl phofl deleted the 38743 branch January 1, 2021 21:33
luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Index Related to the Index class or subclasses Interval Interval data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: IntervalIndex intersections are not intersections in many cases
3 participants