Skip to content

ENH: Addition of input arguments for boundaries to add more consistency between methods #40627

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

Closed
wants to merge 8 commits into from
7 changes: 5 additions & 2 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,15 +1830,18 @@ def validate_endpoints(closed):
left_closed = False
right_closed = False

if closed is None:
if closed is None or closed == True or closed == "neither":
left_closed = True
right_closed = True
elif closed == "left":
left_closed = True
elif closed == "right":
right_closed = True
elif closed == "both" or closed == False:
left_closed = False
right_closed = False
else:
raise ValueError("Closed has to be either 'left', 'right' or None")
raise ValueError("Closed has to be either 'left', 'right', 'neither', 'both' or None, or a boolean value")

return left_closed, right_closed

Expand Down
16 changes: 13 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4684,7 +4684,8 @@ def between(self, left, right, inclusive=True) -> Series:
Left boundary.
right : scalar or list-like
Right boundary.
inclusive : bool, default True
inclusive : str, default "True"

Include boundaries.

Returns
Expand Down Expand Up @@ -4736,12 +4737,21 @@ def between(self, left, right, inclusive=True) -> Series:
3 False
dtype: bool
"""
if inclusive:

if inclusive == True or inclusive == "both":
lmask = self >= left
rmask = self <= right
else:
elif inclusive == "left":
lmask = self >= left
rmask = self < right
elif inclusive == "right":
lmask = self > left
rmask = self <= right
elif inclusive == False or inclusive == "neither":
lmask = self > left
rmask = self < right
else:
raise ValueError("Input should be boolean or string of 'both', 'left', 'right', or 'neither'")

return lmask & rmask

Expand Down