-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Datetime column can't be compared with datetime.date object #41459
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
Comments
The code runs exactly as you expected but raises a FutureWarning in an older version of Pandas. I believe your suggestion is reasonable. However, maybe some technical issues force the team to make this change. Here is the output:
|
The column/Series behavior was changed (deprecated) to match the Timestamp behavior, which was changed a) to match the stdlib datetime behavior and b) because it has wacky behavior when comparing a datetime.date object vs a tzaware Timestamp |
Thanks for the report, but as mentioned this behavior was specifically deprecated as pandas is aligning with standard library behavior. Closing as the expected behavior. |
This makes for a quite strange api that from an user point of view makes little sense: import pandas as pd
import datetime as dt
ts = pd.to_datetime(['2023-03-16T13:00:00+01'])
d = dt.date(2023, 3, 15)
ts > d.isoformat() # ok
ts > d # error Why an isoformat string is ok and a date is not? both contain the same information |
We follow the standard library datetime.datetime behavior which considers dates and datetimes non-comparable. |
My point was that if compare timestamp to a date is an error, then compare to a iso format date should also error. I was not debating the validity of the error here, only the inconsistency in when the error is raised. (personally I find it annoying that it's not supported, but being consistent with the standard library is a fine position to have) |
First, to all maintainers, thank you for your hard work! Pandas is a lifesaver.
Code Sample, a copy-pastable example
Output
Rest of traceback:
Problem description
It seems reasonable to expect that if a pandas datetime column can be compared to a date string, that it should be able to be compared to a date object with exactly the same information. I see this recent PR which if I'm reading it right made it so that a pandas Timestamp won't EQUAL a date object to match stdlib behavior, which I'm fine with...users should expect equality to be really picky. However, if the goal is to match stdlib behavior, we probably shouldn't allow equality between pandas Timestamps and strings either. All that aside, my main point is that if greater than/less than comparisons are allowed between Timestamps and date strings, they should be allowed between Timestamps and date objects.
Expected Output
Output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: