Skip to content

Commit 2e6fa28

Browse files
committed
Move is_monotonic_inc to IntervalTree
1 parent ceb91f3 commit 2e6fa28

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pandas/_libs/intervaltree.pxi.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Template for intervaltree
44
WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
55
"""
66

7+
from pandas._libs.algos import is_monotonic
8+
79
ctypedef fused scalar_t:
810
float64_t
911
float32_t
@@ -101,6 +103,17 @@ cdef class IntervalTree(IntervalMixin):
101103

102104
return self._is_overlapping
103105

106+
@property
107+
def is_monotonic_increasing(self):
108+
"""
109+
Return True if the IntervalTree is monotonic increasing (only equal or
110+
increasing values), else False
111+
"""
112+
values = [self.right, self.left]
113+
114+
sort_order = np.lexsort(values)
115+
return is_monotonic(sort_order, False)[0]
116+
104117
def get_loc(self, scalar_t key):
105118
"""Return all positions corresponding to intervals that overlap with
106119
the given scalar key

pandas/core/indexes/interval.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from pandas._config import get_option
88

99
from pandas._libs import Timedelta, Timestamp
10-
from pandas._libs.algos import is_monotonic
1110
from pandas._libs.interval import Interval, IntervalMixin, IntervalTree
1211
from pandas.compat import add_metaclass
1312
from pandas.util._decorators import Appender, cache_readonly
@@ -450,10 +449,7 @@ def is_monotonic_increasing(self):
450449
Return True if the IntervalIndex is monotonic increasing (only equal or
451450
increasing values), else False
452451
"""
453-
values = [self.right, self.left]
454-
455-
sort_order = np.lexsort(values)
456-
return is_monotonic(sort_order, False)[0]
452+
return self._engine.is_monotonic_increasing
457453

458454
@cache_readonly
459455
def is_monotonic_decreasing(self):

0 commit comments

Comments
 (0)