7272 validate_ascending ,
7373 validate_bool_kwarg ,
7474 validate_fillna_kwargs ,
75+ validate_inclusive ,
7576)
7677
7778from pandas .core .dtypes .common import (
@@ -7694,16 +7695,18 @@ def between_time(
76947695 if not isinstance (index , DatetimeIndex ):
76957696 raise TypeError ("Index must be DatetimeIndex" )
76967697
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 :
77007703 raise ValueError (
77017704 "Deprecated arguments `include_start` and `include_end` "
77027705 "cannot be passed if `inclusive` has been given."
77037706 )
77047707 # If any of the deprecated arguments ('include_start', 'include_end')
77057708 # have been passed
7706- elif ( include_start != lib . no_default ) or ( include_end != lib . no_default ) :
7709+ elif old_include_arg_used :
77077710 warnings .warn (
77087711 "`include_start` and `include_end` are deprecated in "
77097712 "favour of `inclusive`." ,
@@ -7720,20 +7723,15 @@ def between_time(
77207723 (False , False ): "neither" ,
77217724 }
77227725 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 )
77327730 indexer = index .indexer_between_time (
77337731 start_time ,
77347732 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 ,
77377735 )
77387736 return self ._take_with_is_copy (indexer , axis = axis )
77397737
0 commit comments