forked from pandas-dev/pandas
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: Fix joining overlapping IntervalIndex objects (pandas-devGH-45661)
Replacing calls to `get_indexer()` with `get_indexer_for()` as `IntervalIndex`es can be unique and overlapping. Similar to pandas-dev#44588
- Loading branch information
1 parent
20d0964
commit 8bedde5
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
|
||
from pandas import ( | ||
IntervalIndex, | ||
MultiIndex, | ||
RangeIndex, | ||
) | ||
import pandas._testing as tm | ||
|
||
|
||
@pytest.fixture | ||
def range_index(): | ||
return RangeIndex(3, name="range_index") | ||
|
||
|
||
@pytest.fixture | ||
def interval_index(): | ||
return IntervalIndex.from_tuples( | ||
[(0.0, 1.0), (1.0, 2.0), (1.5, 2.5)], name="interval_index" | ||
) | ||
|
||
|
||
def test_join_overlapping_in_mi_to_same_intervalindex(range_index, interval_index): | ||
# GH-45661 | ||
multi_index = MultiIndex.from_product([interval_index, range_index]) | ||
result = multi_index.join(interval_index) | ||
|
||
tm.assert_index_equal(result, multi_index) | ||
|
||
|
||
def test_join_overlapping_to_multiindex_with_same_interval(range_index, interval_index): | ||
# GH-45661 | ||
multi_index = MultiIndex.from_product([interval_index, range_index]) | ||
result = interval_index.join(multi_index) | ||
|
||
tm.assert_index_equal(result, multi_index) | ||
|
||
|
||
def test_join_overlapping_interval_to_another_intervalindex(interval_index): | ||
# GH-45661 | ||
flipped_interval_index = interval_index[::-1] | ||
result = interval_index.join(flipped_interval_index) | ||
|
||
tm.assert_index_equal(result, interval_index) |