@@ -8,6 +8,8 @@ import warnings
8
8
from pandas._libs import lib
9
9
from pandas._libs.algos import is_monotonic
10
10
11
+ from pandas._libs.interval import _warning_interval
12
+
11
13
ctypedef fused int_scalar_t:
12
14
int64_t
13
15
float64_t
@@ -40,13 +42,18 @@ cdef class IntervalTree(IntervalMixin):
40
42
object _is_overlapping, _left_sorter, _right_sorter
41
43
Py_ssize_t _na_count
42
44
43
- def __init__(self, left, right, inclusive: str | None = None, leaf_size=100):
45
+ def __init__(self, left, right, inclusive: str | None = None, closed: None | lib.NoDefault = lib.no_default, leaf_size=100):
44
46
"""
45
47
Parameters
46
48
----------
47
49
left, right : np.ndarray[ndim=1]
48
50
Left and right bounds for each interval. Assumed to contain no
49
51
NaNs.
52
+ closed : {'left', 'right', 'both', 'neither'}, optional
53
+ Whether the intervals are closed on the left-side, right-side, both
54
+ or neither. Defaults to 'right'.
55
+
56
+ .. deprecated:: 1.5.0
50
57
51
58
inclusive : {"both", "neither", "left", "right"}, optional
52
59
Whether the intervals are closed on the left-side, right-side, both
@@ -59,6 +66,8 @@ cdef class IntervalTree(IntervalMixin):
59
66
to brute-force search. Tune this parameter to optimize query
60
67
performance.
61
68
"""
69
+ inclusive, closed = _warning_interval(inclusive, closed)
70
+
62
71
if inclusive is None:
63
72
inclusive = "right"
64
73
@@ -110,7 +119,7 @@ cdef class IntervalTree(IntervalMixin):
110
119
if self._is_overlapping is not None:
111
120
return self._is_overlapping
112
121
113
- # <= when inclusive on both sides since endpoints can overlap
122
+ # <= when both sides closed since endpoints can overlap
114
123
op = le if self.inclusive == 'both' else lt
115
124
116
125
# overlap if start of current interval < end of previous interval
@@ -254,7 +263,7 @@ cdef class IntervalNode:
254
263
255
264
256
265
# we need specialized nodes and leaves to optimize for different dtype and
257
- # inclusive values
266
+ # closed values
258
267
259
268
{{py:
260
269
0 commit comments