-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
DatetimeIndex get_loc validates date object #35478
Conversation
87c400b
to
1d6f0ca
Compare
@@ -152,7 +152,7 @@ class DatetimeArray(dtl.DatetimeLikeArrayMixin, dtl.TimelikeOps, dtl.DatelikeOps | |||
|
|||
_typ = "datetimearray" | |||
_scalar_type = Timestamp | |||
_recognized_scalars = (datetime, np.datetime64) | |||
_recognized_scalars = (datetime, np.datetime64, date) |
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 is the right way to address #35466, but you also need to look at the other places where _recognized_scalars is used and make sure those tests are updated appropriately
Do we want |
@jbrockmendel feel free to catch this, looks like you have been working with the flow on GH#19800 and GH#19301. But having dti == date, looks ok, since the date is timestamped after. |
@knabben can you add a release note to doc\source\whatsnew\v1.1.1.rst |
It's not clear to me that the behavior on master is incorrect. Shouldn't we be following the behavior of Python's In [18]: d = {datetime.datetime(2000, 1, 1): 1}
In [19]: datetime.date(2000, 1, 1) in d
Out[19]: False |
I had the same question in the issue, maybe a date in DateTimeIndex should never be considered and this now should be the correct behavior, this is clear after adding, date in the recognized_scalars, started to break a lot of tests, that were not expecting this to be there (like blocks, internals, etc):
It was passing before because get_loc, was using a fallback for this translation. |
I think get_loc needs to match __eq__, which needs to match
Timestamp.__eq__. I think ATM Timestamp doesn’t match stdlib datetime
behavior, which id be OK with changing (following deprecation cycle)
…On Fri, Jul 31, 2020 at 2:37 PM Amim Knabben ***@***.***> wrote:
It's not clear to me that the behavior on master is incorrect. Shouldn't
we be following the behavior of Python's dict, which doesn't consider
dates to be datetimes at midnight?
In [18]: d = {datetime.datetime(2000, 1, 1): 1}
In [19]: datetime.date(2000, 1, 1) in dOut[19]: False
I had the same question in the issue, maybe a date in DateTimeIndex should
never be considered and this now should be the correct behavior, this is
clear that after adding, *date*:
_recognized_scalars = (datetime, np.datetime64, date)
Break a lot of tests, that were not expecting this to be there (like
blocks, internals, etc), it was passing because get_loc, was using a
fallback for this translation.
cc @jbrockmendel <https://github.com/jbrockmendel>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#35478 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB5UM6HQJM6Y2HNWY4JTKJDR6M2QLANCNFSM4PN7Q52Q>
.
|
closing the PR for the lack of time to investigate it further, for those going on:
|
Indeed, right now, Timestamp considers a
So I think if we want to change this to False, that should go through a deprecation cycle, and the same for the indexing behaviour. |
Although that for Index/Array, we return False ...
|
Just tested this PR to see if it would fix the original issue, it looks like it still doesn't :( >>> datetime.date(2000,1,1) in pd.DatetimeIndex(['2000-01-01'])
False |
It also looks like Timestamp fails to raise TypeError when doing checking Also looks like |
@knabben can you merge master |
-1, DTI.get_loc should raise on a date object. xref #36131 |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Adding the date object try cast in get_loc.