diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 0c841078fe9b4..87dd369a8d9aa 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -338,6 +338,7 @@ Other Deprecations - Deprecated the ``index`` argument to :class:`SparseArray` construction (:issue:`23089`) - Deprecated the ``closed`` argument in :meth:`date_range` and :meth:`bdate_range` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`) - Deprecated :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`) +- Deprecated the 'include_start' and 'include_end' arguments in :meth:`DatetimeIndex.indexer_between_time`; in a future version passing 'include_start' or 'include_end' will raise (:issue:`43602`) - Deprecated silent dropping of columns that raised a ``TypeError`` in :class:`Series.transform` and :class:`DataFrame.transform` when used with a dictionary (:issue:`43740`) - Deprecated silent dropping of columns that raised a ``TypeError``, ``DataError``, and some cases of ``ValueError`` in :meth:`Series.aggregate`, :meth:`DataFrame.aggregate`, :meth:`Series.groupby.aggregate`, and :meth:`DataFrame.groupby.aggregate` when used with a list (:issue:`43740`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index af8c64d5c0202..83b2d76d49169 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -72,7 +72,6 @@ validate_ascending, validate_bool_kwarg, validate_fillna_kwargs, - validate_inclusive, ) from pandas.core.dtypes.common import ( @@ -7832,13 +7831,7 @@ def between_time( elif inclusive is None: # On arg removal inclusive can default to "both" inclusive = "both" - left_inclusive, right_inclusive = validate_inclusive(inclusive) - indexer = index.indexer_between_time( - start_time, - end_time, - include_start=left_inclusive, - include_end=right_inclusive, - ) + indexer = index.indexer_between_time(start_time, end_time, inclusive) return self._take_with_is_copy(indexer, axis=axis) @doc(**_shared_doc_kwargs) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index d556466554ea4..dd7f2a08fa939 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -822,7 +822,7 @@ def indexer_at_time(self, time, asof: bool = False) -> npt.NDArray[np.intp]: return (time_micros == micros).nonzero()[0] def indexer_between_time( - self, start_time, end_time, include_start: bool = True, include_end: bool = True + self, start_time, end_time, inclusive="both" ) -> npt.NDArray[np.intp]: """ Return index locations of values between particular times of day @@ -834,8 +834,8 @@ def indexer_between_time( Time passed either as object (datetime.time) or as string in appropriate format ("%H:%M", "%H%M", "%I:%M%p", "%I%M%p", "%H:%M:%S", "%H%M%S", "%I:%M:%S%p","%I%M%S%p"). - include_start : bool, default True - include_end : bool, default True + inclusive : {"both", "neither", "left", "right"}, default "both" + Include boundaries; whether to set each bound as closed or open. Returns ------- @@ -852,12 +852,12 @@ def indexer_between_time( start_micros = _time_to_micros(start_time) end_micros = _time_to_micros(end_time) - if include_start and include_end: + if inclusive == "both": lop = rop = operator.le - elif include_start: + elif inclusive == "left": lop = operator.le rop = operator.lt - elif include_end: + elif inclusive == "right": lop = operator.lt rop = operator.le else: