Skip to content

Commit dba2080

Browse files
authored
Bug: Incorrect IntervalIndex.is_overlapping (#49933)
* fix left_sorter to support duplicate left values * fix style * add regression test case * add doc * change np.argsort to np.lexsort * remove an unintentionally committed file Co-authored-by: joelchen <joelchen@umich.edu>
1 parent f7fad77 commit dba2080

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ Strings
701701

702702
Interval
703703
^^^^^^^^
704-
-
704+
- Bug in :meth:`IntervalIndex.is_overlapping` incorrect output if interval has duplicate left boundaries (:issue:`49581`)
705705
-
706706

707707
Indexing

pandas/_libs/intervaltree.pxi.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ cdef class IntervalTree(IntervalMixin):
8181
"""How to sort the left labels; this is used for binary search
8282
"""
8383
if self._left_sorter is None:
84-
self._left_sorter = np.argsort(self.left)
84+
values = [self.right, self.left]
85+
self._left_sorter = np.lexsort(values)
8586
return self._left_sorter
8687

8788
@property

pandas/tests/indexes/interval/test_interval.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,13 @@ def test_is_overlapping(self, start, shift, na_value, closed):
791791
result = index.is_overlapping
792792
assert result is expected
793793

794+
# intervals with duplicate left values
795+
a = [10, 15, 20, 25, 30, 35, 40, 45, 45, 50, 55, 60, 65, 70, 75, 80, 85]
796+
b = [15, 20, 25, 30, 35, 40, 45, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90]
797+
index = IntervalIndex.from_arrays(a, b, closed="right")
798+
result = index.is_overlapping
799+
assert result is False
800+
794801
@pytest.mark.parametrize(
795802
"tuples",
796803
[

0 commit comments

Comments
 (0)