Skip to content

DEPR: Disallow Series.between(inclusive=bool) #49570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ Removal of prior version deprecations/changes
- Removed ``pandas.SparseSeries`` and ``pandas.SparseDataFrame``, including pickle support. (:issue:`30642`)
- Enforced disallowing passing an integer ``fill_value`` to :meth:`DataFrame.shift` and :meth:`Series.shift`` with datetime64, timedelta64, or period dtypes (:issue:`32591`)
- Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`)
- Enforced disallowing passing ``True`` and ``False`` into ``inclusive`` in :meth:`Series.between` in favor of ``"both"`` and ``"neither"`` respectively (:issue:`40628`)
- Enforced disallowing using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
- Enforced disallowing the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`)
- Enforced disallowing a tuple of column labels into :meth:`.DataFrameGroupBy.__getitem__` (:issue:`30546`)
Expand Down
13 changes: 0 additions & 13 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5427,19 +5427,6 @@ def between(
3 False
dtype: bool
"""
# error: Non-overlapping identity check (left operand type: "Literal['both',
# 'neither', 'left', 'right']", right operand type: "Literal[False]")
if inclusive is True or inclusive is False: # type: ignore[comparison-overlap]
warnings.warn(
"Boolean inputs to the `inclusive` argument are deprecated in "
"favour of `both` or `neither`.",
FutureWarning,
stacklevel=find_stack_level(),
)
if inclusive:
inclusive = "both"
else:
inclusive = "neither"
if inclusive == "both":
lmask = self >= left
rmask = self <= right
Expand Down
21 changes: 6 additions & 15 deletions pandas/tests/series/methods/test_between.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def test_between_period_values(self):
expected = (ser >= left) & (ser <= right)
tm.assert_series_equal(result, expected)

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

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

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

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

with pytest.raises(ValueError, match=value_error_msg):
series = Series(date_range("1/1/2000", periods=10))
series.between(left, right, inclusive="yes")

def test_between_inclusive_warning(self):
series = Series(date_range("1/1/2000", periods=10))
left, right = series[[2, 7]]
with tm.assert_produces_warning(FutureWarning):
result = series.between(left, right, inclusive=False)
expected = (series > left) & (series < right)
tm.assert_series_equal(result, expected)
with tm.assert_produces_warning(FutureWarning):
result = series.between(left, right, inclusive=True)
expected = (series >= left) & (series <= right)
tm.assert_series_equal(result, expected)
series.between(left, right, inclusive=inclusive)