Skip to content

Date time index.indexer between time #43602

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down
9 changes: 1 addition & 8 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
validate_ascending,
validate_bool_kwarg,
validate_fillna_kwargs,
validate_inclusive,
)

from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is public api, need to deprecate the inlucde_start/end args.

Copy link
Contributor Author

@suyashgupta01 suyashgupta01 Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what do I need to do here. Here's what I think I should do:
(1) Add a deprecate directive for old args (include_start, include_end).
(2) Add a line to show deprecation of old args in whatsnew.

An issue with (1) is that the only function calling indexer_between_time is between_time. So, maintaining functionality with old args would just be extra code as we can just modify between_time and pass inclusive instead of include_start, include_end when indexer_between_time is called.

Please let me know what do you think @jreback :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. yes
  2. yes

then what you do is you change the call to indexer_between_time`` to use the *new* api (so you don't get a deprecation warning in between_time`

) -> npt.NDArray[np.intp]:
"""
Return index locations of values between particular times of day
Expand All @@ -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
-------
Expand All @@ -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:
Expand Down