-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: Timestamp == date match stdlib #36131
BUG: Timestamp == date match stdlib #36131
Conversation
…g-timestamp-cmp-date
…g-timestamp-cmp-date
Seems reasonable. In general do you think we should reel back |
Yes. I think indexing should behave like comparisons, in which case date objects would not be allowed. If we were to allow date objects in indexing, I think it would make more sense to treat |
Shouldn't we rather see this as an API change than a bug fix? |
That's conceivable, but I think its much more likely that people are assuming that it casts to datetime-at-midnight and so are silently getting incorrect results. |
Well, and they will then also start to see a warning to make them aware of this. Now, it's not only about the "timestamp getting normalized to midnight when compared to date" behaviour, because as I understand it with this PR also Timestamps as midnight will no longer compare equal? I think we should first deprecate that. |
…g-timestamp-cmp-date
…g-timestamp-cmp-date
…g-timestamp-cmp-date
Updated to deprecate. |
pandas/tests/groupby/test_apply.py
Outdated
@@ -1065,7 +1065,9 @@ def test_apply_with_date_in_multiindex_does_not_convert_to_timestamp(): | |||
) | |||
|
|||
grp = df.groupby(["A", "B"]) | |||
result = grp.apply(lambda x: x.head(1)) | |||
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
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.
we are exposing this to the user?
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.
any idea why this happens?
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.
when it tries to make a MultiIndex out of the A and B columns, it goes through Categorical, which passes convert_dates=True to maybe_infer_to_datetimelike,
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 not be warnign at the top level
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.
we could finagle it so that we dont pass convert_dates=True to maybe_infer_to_datetimelike in this case, but that gets pretty complicated, especially compared to just warning the user that date objects are finicky
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.
Looks like a while back you were in favor of telling people not to pass dates to the MultiIndex constructors.
btw do we have an actual issue for this? (that this PR would close) |
There are still some warnings raised by the tests. For example in the github actions build I see:
|
…g-timestamp-cmp-date
Huh, why isnt that failing the npdev build? |
Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
…as into bug-timestamp-cmp-date
Updated test_get_indexer_out_of_bounds_date to catch the warning. Weird thing is that locally every-other-run it fails saying it the expected warning was not emitted. |
now builds are failing because of warnings |
harumph, yah that looks like the same thing where that was happening every-other-run locally |
…g-timestamp-cmp-date
…g-timestamp-cmp-date
suppressed the warning, green |
Why can the warning be suppressed in the tests? It's not a valid user case? |
its flaky and i haven't figured out why |
thanks @jbrockmendel |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
ATM we have one reasonable behavior
Timestamp("2020-09-04") == date(2020, 9, 4)
and two un-reasonable behaviors: ``Timestamp("2020-09-04").tz_localize("US/Pacific") == date(2020, 9, 4),
Timestamp.now() == Timestamp.now().date()`. Since the stdlib datetime doesnt consider `datetime(2020, 9, 4) == date(2020, 9, 4)`, this follows the stdlib and considers them never equal.I'm still getting one test failure locally.cc @mroeschke