Skip to content

Commit 5700d93

Browse files
committed
Revert "DEPR: Remove deprecation from private class IntervalTree (pandas-dev#47637)"
This reverts commit f6658ef.
1 parent b2bfe3b commit 5700d93

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

pandas/_libs/intervaltree.pxi.in

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import warnings
88
from pandas._libs import lib
99
from pandas._libs.algos import is_monotonic
1010

11+
from pandas._libs.interval import _warning_interval
12+
1113
ctypedef fused int_scalar_t:
1214
int64_t
1315
float64_t
@@ -40,13 +42,18 @@ cdef class IntervalTree(IntervalMixin):
4042
object _is_overlapping, _left_sorter, _right_sorter
4143
Py_ssize_t _na_count
4244

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):
4446
"""
4547
Parameters
4648
----------
4749
left, right : np.ndarray[ndim=1]
4850
Left and right bounds for each interval. Assumed to contain no
4951
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
5057

5158
inclusive : {"both", "neither", "left", "right"}, optional
5259
Whether the intervals are closed on the left-side, right-side, both
@@ -59,6 +66,8 @@ cdef class IntervalTree(IntervalMixin):
5966
to brute-force search. Tune this parameter to optimize query
6067
performance.
6168
"""
69+
inclusive, closed = _warning_interval(inclusive, closed)
70+
6271
if inclusive is None:
6372
inclusive = "right"
6473

@@ -110,7 +119,7 @@ cdef class IntervalTree(IntervalMixin):
110119
if self._is_overlapping is not None:
111120
return self._is_overlapping
112121

113-
# <= when inclusive on both sides since endpoints can overlap
122+
# <= when both sides closed since endpoints can overlap
114123
op = le if self.inclusive == 'both' else lt
115124

116125
# overlap if start of current interval < end of previous interval
@@ -254,7 +263,7 @@ cdef class IntervalNode:
254263

255264

256265
# we need specialized nodes and leaves to optimize for different dtype and
257-
# inclusive values
266+
# closed values
258267

259268
{{py:
260269

pandas/tests/indexes/interval/test_interval_tree.py

+18
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,24 @@ def test_construction_overflow(self):
190190
expected = (50 + np.iinfo(np.int64).max) / 2
191191
assert result == expected
192192

193+
def test_interval_tree_error_and_warning(self):
194+
# GH 40245
195+
196+
msg = (
197+
"Deprecated argument `closed` cannot "
198+
"be passed if argument `inclusive` is not None"
199+
)
200+
with pytest.raises(ValueError, match=msg):
201+
left, right = np.arange(10), [np.iinfo(np.int64).max] * 10
202+
IntervalTree(left, right, closed="both", inclusive="both")
203+
204+
msg = "Argument `closed` is deprecated in favor of `inclusive`"
205+
with tm.assert_produces_warning(
206+
FutureWarning, match=msg, check_stacklevel=False
207+
):
208+
left, right = np.arange(10), [np.iinfo(np.int64).max] * 10
209+
IntervalTree(left, right, closed="both")
210+
193211
@pytest.mark.xfail(not IS64, reason="GH 23440")
194212
@pytest.mark.parametrize(
195213
"left, right, expected",

0 commit comments

Comments
 (0)