-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
BUG: Date objects cannot be compared against a DatetimeIndex #35466
Comments
Thanks @knabben for the report
#31023 is the cause of this regression, so doesn't appear to be an intentional change cc @jbrockmendel 9b0ef5d is the first bad commit
|
this needs more discussion |
I hope this gets more attention. This also broke DataFrame/Series indexing: >>> date = datetime.date(2000, 1, 1)
>>> s = pd.Series([1], index=pd.to_datetime([date]))
>>> s.loc['2000-01-01']
1
>>> s.loc[date]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dwardzinski/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 879, in __getitem__
return self._getitem_axis(maybe_callable, axis=axis)
File "/home/dwardzinski/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 1110, in _getitem_axis
return self._get_label(key, axis=axis)
File "/home/dwardzinski/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 1059, in _get_label
return self.obj.xs(label, axis=axis)
File "/home/dwardzinski/.local/lib/python3.8/site-packages/pandas/core/generic.py", line 3482, in xs
loc = self.index.get_loc(key)
File "/home/dwardzinski/.local/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py", line 622, in get_loc
raise KeyError(key)
KeyError: datetime.date(2000, 1, 1) This broke a lot of stuff for me, since my software relies pretty heavily on indexing with date objects. |
there is not a PR to actually change this, nor has this been discussed, moving off 1.2 |
The current behavior of DatetimeIndex refusing to compare to a |
should this behaviour be deprecated first? and for the indexing case, #35466 (comment) (maybe need to create separate issue), is KeyError appropriate or would TypeError now be more appropriate. to be consistent with Python list indexing...
perhaps something like |
In 1.1.0 we made it so that failed label-based lookups always raise KeyError (see _whatsnew_110.notable_bug_fixes.indexing_raises_key_errors) |
So, what are the plans wrt this? |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Version 1.0.5
Version 1.1.0
Problem description
On version 1.0.5 it was possible to compare via contains a datetime.date object against a DatetimeIndex, this behavior is not true anymore for the 1.1.0, is this an expected behavior to allow only recognized scalars objects?
Expected Output
Allow dates to be compared with 00:00:00 time.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : d9fff27
python : 3.6
OS : Darwin
pandas : 1.1.0
numpy : 1.19.1
Cython : None
The text was updated successfully, but these errors were encountered: