Skip to content

Commit 67ce770

Browse files
authored
DEPR: Disallow Series.between(inclusive=bool) (#49570)
DEPR: Series.between(inclusive=bool)
1 parent bb7dd2c commit 67ce770

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ Removal of prior version deprecations/changes
401401
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame``, including pickle support. (:issue:`30642`)
402402
- Enforced disallowing passing an integer ``fill_value`` to :meth:`DataFrame.shift` and :meth:`Series.shift`` with datetime64, timedelta64, or period dtypes (:issue:`32591`)
403403
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
404+
- Enforced disallowing passing ``True`` and ``False`` into ``inclusive`` in :meth:`Series.between` in favor of ``"both"`` and ``"neither"`` respectively (:issue:`40628`)
404405
- Enforced disallowing using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
405406
- Enforced disallowing the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`)
406407
- Enforced disallowing a tuple of column labels into :meth:`.DataFrameGroupBy.__getitem__` (:issue:`30546`)

pandas/core/series.py

-13
Original file line numberDiff line numberDiff line change
@@ -5427,19 +5427,6 @@ def between(
54275427
3 False
54285428
dtype: bool
54295429
"""
5430-
# error: Non-overlapping identity check (left operand type: "Literal['both',
5431-
# 'neither', 'left', 'right']", right operand type: "Literal[False]")
5432-
if inclusive is True or inclusive is False: # type: ignore[comparison-overlap]
5433-
warnings.warn(
5434-
"Boolean inputs to the `inclusive` argument are deprecated in "
5435-
"favour of `both` or `neither`.",
5436-
FutureWarning,
5437-
stacklevel=find_stack_level(),
5438-
)
5439-
if inclusive:
5440-
inclusive = "both"
5441-
else:
5442-
inclusive = "neither"
54435430
if inclusive == "both":
54445431
lmask = self >= left
54455432
rmask = self <= right

pandas/tests/series/methods/test_between.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def test_between_period_values(self):
3838
expected = (ser >= left) & (ser <= right)
3939
tm.assert_series_equal(result, expected)
4040

41-
def test_between_inclusive_string(self): # :issue:`40628`
41+
def test_between_inclusive_string(self):
42+
# GH 40628
4243
series = Series(date_range("1/1/2000", periods=10))
4344
left, right = series[[2, 7]]
4445

@@ -58,7 +59,9 @@ def test_between_inclusive_string(self): # :issue:`40628`
5859
expected = (series > left) & (series < right)
5960
tm.assert_series_equal(result, expected)
6061

61-
def test_between_error_args(self): # :issue:`40628`
62+
@pytest.mark.parametrize("inclusive", ["yes", True, False])
63+
def test_between_error_args(self, inclusive):
64+
# GH 40628
6265
series = Series(date_range("1/1/2000", periods=10))
6366
left, right = series[[2, 7]]
6467

@@ -69,16 +72,4 @@ def test_between_error_args(self): # :issue:`40628`
6972

7073
with pytest.raises(ValueError, match=value_error_msg):
7174
series = Series(date_range("1/1/2000", periods=10))
72-
series.between(left, right, inclusive="yes")
73-
74-
def test_between_inclusive_warning(self):
75-
series = Series(date_range("1/1/2000", periods=10))
76-
left, right = series[[2, 7]]
77-
with tm.assert_produces_warning(FutureWarning):
78-
result = series.between(left, right, inclusive=False)
79-
expected = (series > left) & (series < right)
80-
tm.assert_series_equal(result, expected)
81-
with tm.assert_produces_warning(FutureWarning):
82-
result = series.between(left, right, inclusive=True)
83-
expected = (series >= left) & (series <= right)
84-
tm.assert_series_equal(result, expected)
75+
series.between(left, right, inclusive=inclusive)

0 commit comments

Comments
 (0)