-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Index.get_slice_bounds does not accept datetime.date or tz naive datetime.datetimes #35848
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
Conversation
@@ -0,0 +1,76 @@ | |||
from datetime import date, datetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this should go in tests.indexes.datetimes.test_indexing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also testing object and numeric Index
es in this file as well. Where should those tests go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id put the object ones in tests.indexes.base_class.test_indexing.TestGetSliceBounds
and the numeric ones in tests.indexes.numeric.test_indexing.TestGetSliceBounds
pandas/core/indexes/datetimes.py
Outdated
@@ -672,6 +672,11 @@ def _maybe_cast_slice_bound(self, label, side: str, kind): | |||
if self._is_strictly_monotonic_decreasing and len(self) > 1: | |||
return upper if side == "left" else lower | |||
return lower if side == "left" else upper | |||
# GH 35690: Ensure the label matches the timezone of the index's tz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll comment in #35690, not entirely sure this is the desired behavior.
Assuming it is the desired behavior, can this casting take place in _maybe_cast_for_get_loc? If not, can you update the docstring to reflect this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure yeah this can probably go in _maybe_cast_for_get_loc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will look soon
pandas/core/indexes/datetimes.py
Outdated
# needed to localize naive datetimes | ||
# needed to localize naive datetimes or dates (GH 35690) | ||
if isinstance(key, date) and not isinstance(key, datetime): | ||
key = datetime.combine(key, time(0, 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't the Timestamp(key)
below do this already?
Just commented on #35690, the upshot of which is that I think the current behavior is correct. |
pandas/core/indexes/base.py
Outdated
if side not in ("left", "right"): | ||
raise ValueError( | ||
"Invalid value for side kwarg, must be either " | ||
f"'left' or 'right': {side}" | ||
) | ||
|
||
if kind not in ("loc", "getitem", None): | ||
raise ValueError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be an AssertionError as this is an internal method (yes I know @RhysU is actually calling it), but its officially public and merely an interface from .loc
Hello @mroeschke! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-09-02 05:43:44 UTC |
lgtm @mroeschke ideally we also test via |
See comment above, this PR should not be merged. |
… datetime.datetimes (pandas-dev#35848)
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
This method appeared under tested so added some additional tests for numeric and object
Index