Skip to content

Commit b2bfe3b

Browse files
committed
Revert "DEPR: Deprecate set_closed and add set_incluive (pandas-dev#47636)"
This reverts commit bd4ff39.
1 parent 10b3032 commit b2bfe3b

File tree

8 files changed

+27
-73
lines changed

8 files changed

+27
-73
lines changed

doc/redirects.csv

-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,6 @@ generated/pandas.IntervalIndex.mid,../reference/api/pandas.IntervalIndex.mid
761761
generated/pandas.IntervalIndex.overlaps,../reference/api/pandas.IntervalIndex.overlaps
762762
generated/pandas.IntervalIndex.right,../reference/api/pandas.IntervalIndex.right
763763
generated/pandas.IntervalIndex.set_closed,../reference/api/pandas.IntervalIndex.set_closed
764-
generated/pandas.IntervalIndex.set_inclusive,../reference/api/pandas.IntervalIndex.set_inclusive
765764
generated/pandas.IntervalIndex.to_tuples,../reference/api/pandas.IntervalIndex.to_tuples
766765
generated/pandas.IntervalIndex.values,../reference/api/pandas.IntervalIndex.values
767766
generated/pandas.Interval.left,../reference/api/pandas.Interval.left

doc/source/reference/arrays.rst

-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ A collection of intervals may be stored in an :class:`arrays.IntervalArray`.
352352
arrays.IntervalArray.contains
353353
arrays.IntervalArray.overlaps
354354
arrays.IntervalArray.set_closed
355-
arrays.IntervalArray.set_inclusive
356355
arrays.IntervalArray.to_tuples
357356

358357

doc/source/reference/indexing.rst

-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ IntervalIndex components
251251
IntervalIndex.get_loc
252252
IntervalIndex.get_indexer
253253
IntervalIndex.set_closed
254-
IntervalIndex.set_inclusive
255254
IntervalIndex.contains
256255
IntervalIndex.overlaps
257256
IntervalIndex.to_tuples

doc/source/whatsnew/v1.5.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ Other Deprecations
830830
- Deprecated the ``closed`` argument in :class:`IntervalIndex` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
831831
- Deprecated the ``closed`` argument in :class:`IntervalDtype` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
832832
- Deprecated the ``closed`` argument in :class:`.IntervalArray` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
833-
- Deprecated :meth:`.IntervalArray.set_closed` and :meth:`.IntervalIndex.set_closed` in favor of ``set_inclusive``; In a future version ``set_closed`` will get removed (:issue:`40245`)
833+
- Deprecated the ``closed`` argument in :class:`IntervalTree` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
834834
- Deprecated the ``closed`` argument in :class:`ArrowInterval` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`)
835835
- Deprecated allowing ``unit="M"`` or ``unit="Y"`` in :class:`Timestamp` constructor with a non-round float value (:issue:`47267`)
836836
- Deprecated the ``display.column_space`` global configuration option (:issue:`7576`)

pandas/core/arrays/interval.py

+3-55
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@
160160
contains
161161
overlaps
162162
set_closed
163-
set_inclusive
164163
to_tuples
165164
%(extra_methods)s\
166165
@@ -1387,11 +1386,9 @@ def closed(self) -> IntervalClosedType:
13871386
"""
13881387
Return an identical %(klass)s closed on the specified side.
13891388
1390-
.. deprecated:: 1.5.0
1391-
13921389
Parameters
13931390
----------
1394-
closed : {'left', 'right', 'both', 'neither'}
1391+
inclusive : {'left', 'right', 'both', 'neither'}
13951392
Whether the intervals are closed on the left-side, right-side, both
13961393
or neither.
13971394
@@ -1424,57 +1421,8 @@ def closed(self) -> IntervalClosedType:
14241421
),
14251422
}
14261423
)
1427-
def set_closed(self: IntervalArrayT, closed: IntervalClosedType) -> IntervalArrayT:
1428-
warnings.warn(
1429-
"set_closed is deprecated and will be removed in a future version. "
1430-
"Use set_inclusive instead.",
1431-
FutureWarning,
1432-
stacklevel=find_stack_level(inspect.currentframe()),
1433-
)
1434-
return self.set_inclusive(closed)
1435-
1436-
_interval_shared_docs["set_inclusive"] = textwrap.dedent(
1437-
"""
1438-
Return an identical %(klass)s but closed on the specified side.
1439-
1440-
.. versionadded:: 1.5
1441-
1442-
Parameters
1443-
----------
1444-
inclusive : {'left', 'right', 'both', 'neither'}
1445-
Whether the intervals are closed on the left-side, right-side, both
1446-
or neither.
1447-
1448-
Returns
1449-
-------
1450-
new_index : %(klass)s
1451-
1452-
%(examples)s\
1453-
"""
1454-
)
1455-
1456-
@Appender(
1457-
_interval_shared_docs["set_inclusive"]
1458-
% {
1459-
"klass": "IntervalArray",
1460-
"examples": textwrap.dedent(
1461-
"""\
1462-
Examples
1463-
--------
1464-
>>> index = pd.arrays.IntervalArray.from_breaks(range(4), "right")
1465-
>>> index
1466-
<IntervalArray>
1467-
[(0, 1], (1, 2], (2, 3]]
1468-
Length: 3, dtype: interval[int64, right]
1469-
>>> index.set_inclusive('both')
1470-
<IntervalArray>
1471-
[[0, 1], [1, 2], [2, 3]]
1472-
Length: 3, dtype: interval[int64, both]
1473-
"""
1474-
),
1475-
}
1476-
)
1477-
def set_inclusive(
1424+
@deprecate_kwarg(old_arg_name="closed", new_arg_name="inclusive")
1425+
def set_closed(
14781426
self: IntervalArrayT, inclusive: IntervalClosedType
14791427
) -> IntervalArrayT:
14801428
if inclusive not in VALID_CLOSED:

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _new_IntervalIndex(cls, d):
180180
),
181181
}
182182
)
183-
@inherit_names(["set_closed", "set_inclusive", "to_tuples"], IntervalArray, wrap=True)
183+
@inherit_names(["set_closed", "to_tuples"], IntervalArray, wrap=True)
184184
@inherit_names(
185185
[
186186
"__array__",

pandas/tests/arrays/interval/test_interval.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def test_is_empty(self, constructor, left, right, closed):
6060

6161

6262
class TestMethods:
63-
@pytest.mark.parametrize("new_inclusive", ["left", "right", "both", "neither"])
64-
def test_set_inclusive(self, closed, new_inclusive):
63+
@pytest.mark.parametrize("new_closed", ["left", "right", "both", "neither"])
64+
def test_set_closed(self, closed, new_closed):
6565
# GH 21670
6666
array = IntervalArray.from_breaks(range(10), inclusive=closed)
67-
result = array.set_inclusive(new_inclusive)
68-
expected = IntervalArray.from_breaks(range(10), inclusive=new_inclusive)
67+
result = array.set_closed(new_closed)
68+
expected = IntervalArray.from_breaks(range(10), inclusive=new_closed)
6969
tm.assert_extension_array_equal(result, expected)
7070

7171
@pytest.mark.parametrize(
@@ -134,10 +134,10 @@ def test_set_na(self, left_right_dtypes):
134134

135135
tm.assert_extension_array_equal(result, expected)
136136

137-
def test_setitem_mismatched_inclusive(self):
137+
def test_setitem_mismatched_closed(self):
138138
arr = IntervalArray.from_breaks(range(4), "right")
139139
orig = arr.copy()
140-
other = arr.set_inclusive("both")
140+
other = arr.set_closed("both")
141141

142142
msg = "'value.inclusive' is 'both', expected 'right'"
143143
with pytest.raises(ValueError, match=msg):
@@ -488,8 +488,17 @@ def test_from_arrays_deprecation():
488488
IntervalArray.from_arrays([0, 1, 2], [1, 2, 3], closed="right")
489489

490490

491-
def test_set_closed_deprecated():
491+
def test_set_closed_deprecated_closed():
492492
# GH#40245
493493
array = IntervalArray.from_breaks(range(10))
494494
with tm.assert_produces_warning(FutureWarning):
495495
array.set_closed(closed="both")
496+
497+
498+
def test_set_closed_both_provided_deprecation():
499+
# GH#40245
500+
array = IntervalArray.from_breaks(range(10))
501+
msg = "Can only specify 'closed' or 'inclusive', not both."
502+
with pytest.raises(TypeError, match=msg):
503+
with tm.assert_produces_warning(FutureWarning):
504+
array.set_closed(inclusive="both", closed="both")

pandas/tests/indexes/interval/test_interval.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -871,21 +871,21 @@ def test_nbytes(self):
871871
expected = 64 # 4 * 8 * 2
872872
assert result == expected
873873

874-
@pytest.mark.parametrize("new_inclusive", ["left", "right", "both", "neither"])
875-
def test_set_inclusive(self, name, closed, new_inclusive):
874+
@pytest.mark.parametrize("new_closed", ["left", "right", "both", "neither"])
875+
def test_set_closed(self, name, closed, new_closed):
876876
# GH 21670
877877
index = interval_range(0, 5, inclusive=closed, name=name)
878-
result = index.set_inclusive(new_inclusive)
879-
expected = interval_range(0, 5, inclusive=new_inclusive, name=name)
878+
result = index.set_closed(new_closed)
879+
expected = interval_range(0, 5, inclusive=new_closed, name=name)
880880
tm.assert_index_equal(result, expected)
881881

882882
@pytest.mark.parametrize("bad_inclusive", ["foo", 10, "LEFT", True, False])
883-
def test_set_inclusive_errors(self, bad_inclusive):
883+
def test_set_closed_errors(self, bad_inclusive):
884884
# GH 21670
885885
index = interval_range(0, 5)
886886
msg = f"invalid option for 'inclusive': {bad_inclusive}"
887887
with pytest.raises(ValueError, match=msg):
888-
index.set_inclusive(bad_inclusive)
888+
index.set_closed(bad_inclusive)
889889

890890
def test_is_all_dates(self):
891891
# GH 23576

0 commit comments

Comments
 (0)