-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Timedelta components no longer rounded with high precision integers #31380
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
Conversation
@@ -859,14 +859,6 @@ cdef class _Timedelta(timedelta): | |||
""" | |||
return self.to_timedelta64() | |||
|
|||
def total_seconds(self): |
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.
No longer need this implementation since we can rely on timedelta.total_seconds
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.
what change for the "no longer" part?
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.
Since we are now dispatching the correct microseconds to datetime.timedelta
here: https://github.com/pandas-dev/pandas/pull/31380/files#diff-d23555c3fb6b3ffc9f2088e09f9ec5f9R1245
we can use datetime.timedelta.total_seconds
as mentioned in this #31155 (comment) since we are no longer rounding.
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.
sounds good, thanks for explaining
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.
FWIW, I did consider suggesting the removal of total_seconds
here, but when I benchmarked it, I found that the implementation where you truncate ._value
was about 2x as fast as the native timedelta.total_seconds()
, if that matters at all.
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.
lgtm
@@ -109,7 +109,7 @@ Datetimelike | |||
Timedelta | |||
^^^^^^^^^ | |||
|
|||
- | |||
- Bug in constructing a :class:`Timedelta` with a high precision integer that would round the :class:`Timedelta` components (:issue:`31354`) |
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.
BTW, I'm not sure if it was already covered by the earlier PR, but it seems like the change in precision to total_seconds()
from "dubiously nanosecond-precision" to "microsecond-precision" should probably show up in the release notes. It seems like this is the only entry under Timedelta
, so maybe it was done silently? Or was the other change already released?
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff