72
72
validate_ascending ,
73
73
validate_bool_kwarg ,
74
74
validate_fillna_kwargs ,
75
+ validate_inclusive ,
75
76
)
76
77
77
78
from pandas .core .dtypes .common import (
@@ -7694,16 +7695,18 @@ def between_time(
7694
7695
if not isinstance (index , DatetimeIndex ):
7695
7696
raise TypeError ("Index must be DatetimeIndex" )
7696
7697
7697
- if (include_start != lib .no_default or include_end != lib .no_default ) and (
7698
- inclusive is not None
7699
- ):
7698
+ old_include_arg_used = (include_start != lib .no_default ) or (
7699
+ include_end != lib .no_default
7700
+ )
7701
+
7702
+ if old_include_arg_used and inclusive is not None :
7700
7703
raise ValueError (
7701
7704
"Deprecated arguments `include_start` and `include_end` "
7702
7705
"cannot be passed if `inclusive` has been given."
7703
7706
)
7704
7707
# If any of the deprecated arguments ('include_start', 'include_end')
7705
7708
# have been passed
7706
- elif ( include_start != lib . no_default ) or ( include_end != lib . no_default ) :
7709
+ elif old_include_arg_used :
7707
7710
warnings .warn (
7708
7711
"`include_start` and `include_end` are deprecated in "
7709
7712
"favour of `inclusive`." ,
@@ -7720,20 +7723,15 @@ def between_time(
7720
7723
(False , False ): "neither" ,
7721
7724
}
7722
7725
inclusive = inc_dict [(left , right )]
7723
- else : # On arg removal inclusive can default to "both"
7724
- if inclusive is None :
7725
- inclusive = "both"
7726
- elif inclusive not in ["both" , "neither" , "left" , "right" ]:
7727
- raise ValueError (
7728
- f"Inclusive has to be either string of 'both', "
7729
- f"'left', 'right', or 'neither'. Got { inclusive } ."
7730
- )
7731
-
7726
+ elif inclusive is None :
7727
+ # On arg removal inclusive can default to "both"
7728
+ inclusive = "both"
7729
+ left_inclusive , right_inclusive = validate_inclusive (inclusive )
7732
7730
indexer = index .indexer_between_time (
7733
7731
start_time ,
7734
7732
end_time ,
7735
- include_start = inclusive in [ "both" , "left" ] ,
7736
- include_end = inclusive in [ "both" , "right" ] ,
7733
+ include_start = left_inclusive ,
7734
+ include_end = right_inclusive ,
7737
7735
)
7738
7736
return self ._take_with_is_copy (indexer , axis = axis )
7739
7737
0 commit comments