-
-
Notifications
You must be signed in to change notification settings - Fork 19k
BUG: Remove special-casing for date objects in DatetimeIndex indexing (GH#62158) #62198
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
base: main
Are you sure you want to change the base?
BUG: Remove special-casing for date objects in DatetimeIndex indexing (GH#62158) #62198
Conversation
@jbrockmendel hi I have a question about handling the new deprecation warning Thanks! |
pandas/core/indexes/datetimes.py
Outdated
# GH#42855 handle date here instead of get_slice_bound | ||
if isinstance(label, dt.date) and not isinstance(label, dt.datetime): | ||
# Pandas supports slicing with dates, treated as datetimes at midnight. | ||
warnings.warn( |
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 dont think this is part of the original issue?
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.
Thank you for the feedback. I have removed the unrelated parts of this issue, and I will look into it further as the checks are still failing.
dti = Index(ser3) | ||
# All should be consistent | ||
assert dti.get_loc(ser[0]) == 0 | ||
tm.assert_numpy_array_equal(dti.get_indexer(ser.values), [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.
the second arg here should be an array, not list
|
||
ts2 = ts.copy() | ||
ts2.index = [x.date() for x in ts2.index] | ||
ts2.index = to_datetime([x.date() for x in ts2.index]) |
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 defeats the purpose of this test
…estamp in indexing and merging tests
…estamp in indexing and merging tests
…estamp in indexing and merging tests
ts2 = ts_slice.copy() | ||
ts2.index = [x.date() for x in ts2.index] | ||
# Explicitly convert date objects to Timestamps for alignment | ||
ts2.index = [pd.Timestamp(x.date()) for x in ts2.index] |
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.
seems like this defeats the purpose of the test
|
||
expected_inner = DataFrame( | ||
[[pd.Timestamp("2001-01-01").date(), 1.1, 1.3]], | ||
[[date(2001, 1, 1), 1.1, 1.3]], |
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.
edits in this file look unnecessary
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.
Thanks , I will remove changes of this file.
|
||
class TestGetIndexer: | ||
def test_get_indexer_date_objs(self): | ||
rng = date_range("1/1/2000", periods=20) |
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.
comment here pointing back to the issue saying the behavior changed
Mostly looks good, will need a whatsnew note |
…et_indexer and update whatsnew note (pandas-dev#62158)
@jbrockmendel Thanks for the feedback! I’ve applied the suggested changes and updated the PR. Please let me know if there’s anything else that needs adjustment. |
This PR resolves (GH#62158) by removing the legacy special-casing for Python date objects in DatetimeIndex indexing logic.
What’s Changed:
Removed the special-case handling of date objects in DatetimeIndex.getitem.
Updated/added tests in pandas/tests/frame/indexing/test_indexing.py to reflect the new, consistent behavior.
Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou !