Skip to content

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

Merged
merged 3 commits into from
Feb 2, 2020

Conversation

mroeschke
Copy link
Member

@mroeschke mroeschke added the Timedelta Timedelta data type label Jan 28, 2020
@@ -859,14 +859,6 @@ cdef class _Timedelta(timedelta):
"""
return self.to_timedelta64()

def total_seconds(self):
Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Contributor

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.

@mroeschke mroeschke added this to the 1.1 milestone Jan 28, 2020
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mroeschke mroeschke merged commit 9fb1f91 into pandas-dev:master Feb 2, 2020
@mroeschke mroeschke deleted the timedelta_precision branch February 2, 2020 21:09
@@ -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`)
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Timedelta components rounded by float imprecision
4 participants