You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that there is some premature rounding happening in the Timedelta constructor that makes it so the unit-adjusted sums of the days, seconds, microseconds and nanoseconds attributes do not sum to the total number of nanoseconds. A fundamental assumption of the datetime.timedelta type (and breaking this assumption breaks Liskov substitutability) is that the total time difference at the precision of microseconds can be represented by summing up the unit-adjusted days, seconds and microseconds attributes, and it's how datetime.total_seconds() works.
I believe that this is the root cause of issue #31043, which was "fixed" with what is essentially a workaround in PR #31155, as I mentioned in this comment.
At the moment the most obvious effect is that bug #31043 only is fixed for recent versions of dateutil, but presumably it will show up in other places where standard datetime arithmetic is being used on pandas timestamps.
The text was updated successfully, but these errors were encountered:
pganssle
changed the title
BUG: Timedelta
BUG: Timedelta components rounded due by float imprecision
Jan 27, 2020
pganssle
changed the title
BUG: Timedelta components rounded due by float imprecision
BUG: Timedelta components rounded by float imprecision
Jan 27, 2020
In [15]: from datetime import timedelta
In [17]: timedelta(microseconds=int(1552211999999999872) / 1000).seconds
Out[17]: 36000
pd.Timedelta actually has private attributes that can compose value accurately, we just need to ensure that the corresponding attributes in datetime.timedelta are passed those
Problem description
It appears that there is some premature rounding happening in the
Timedelta
constructor that makes it so the unit-adjusted sums of thedays
,seconds
,microseconds
andnanoseconds
attributes do not sum to the total number of nanoseconds. A fundamental assumption of thedatetime.timedelta
type (and breaking this assumption breaks Liskov substitutability) is that the total time difference at the precision of microseconds can be represented by summing up the unit-adjusteddays
,seconds
andmicroseconds
attributes, and it's howdatetime.total_seconds()
works.I believe that this is the root cause of issue #31043, which was "fixed" with what is essentially a workaround in PR #31155, as I mentioned in this comment.
At the moment the most obvious effect is that bug #31043 only is fixed for recent versions of
dateutil
, but presumably it will show up in other places where standarddatetime
arithmetic is being used onpandas
timestamps.Code Sample, a copy-pastable example if possible
Actual output:
Expected output
The text was updated successfully, but these errors were encountered: