Skip to content

Commit cc6b24d

Browse files
authored
Merge pull request #1 from hewittk/new-boundary-inputs
New boundary inputs
2 parents 3888a3f + c87e240 commit cc6b24d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1830,13 +1830,16 @@ def validate_endpoints(closed):
18301830
left_closed = False
18311831
right_closed = False
18321832

1833-
if closed is None:
1833+
if closed is None or closed == "True":
18341834
left_closed = True
18351835
right_closed = True
18361836
elif closed == "left":
18371837
left_closed = True
18381838
elif closed == "right":
18391839
right_closed = True
1840+
elif closed == "both" or closed == "False":
1841+
left_closed = False
1842+
right_closed = False
18401843
else:
18411844
raise ValueError("Closed has to be either 'left', 'right' or None")
18421845

pandas/core/series.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4670,7 +4670,7 @@ def isin(self, values) -> Series:
46704670
self, method="isin"
46714671
)
46724672

4673-
def between(self, left, right, inclusive=True) -> Series:
4673+
def between(self, left, right, inclusive="True") -> Series:
46744674
"""
46754675
Return boolean Series equivalent to left <= series <= right.
46764676
@@ -4684,7 +4684,8 @@ def between(self, left, right, inclusive=True) -> Series:
46844684
Left boundary.
46854685
right : scalar or list-like
46864686
Right boundary.
4687-
inclusive : bool, default True
4687+
inclusive : str, default "True"
4688+
46884689
Include boundaries.
46894690
46904691
Returns
@@ -4736,12 +4737,21 @@ def between(self, left, right, inclusive=True) -> Series:
47364737
3 False
47374738
dtype: bool
47384739
"""
4739-
if inclusive:
4740+
4741+
if inclusive == "True" or inclusive == "both":
47404742
lmask = self >= left
47414743
rmask = self <= right
4742-
else:
4744+
elif inclusive == "left":
4745+
lmask = self >= left
4746+
rmask = self < right
4747+
elif inclusive == "right":
4748+
lmask = self > left
4749+
rmask = self <= right
4750+
elif inclusive == "False":
47434751
lmask = self > left
47444752
rmask = self < right
4753+
else:
4754+
raise ValueError("String input of 'True', 'both' 'False' 'left', 'right', should be submitted")
47454755

47464756
return lmask & rmask
47474757

0 commit comments

Comments
 (0)