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: conversion precision on Timedeltas #14156

jreback opened this Issue Sep 5, 2016 · 3 comments


None yet
3 participants

jreback commented Sep 5, 2016

I think this is rounding prematurely, though not entirely sure. Could also just be loss of precision when converting from a float -> int64.

In [12]: pd.to_datetime(1434743731.8770001,unit='s')
Out[12]: Timestamp('2015-06-19 19:55:31.877000')

In [13]: pd.to_datetime(1434743731.8770001,unit='s').value
Out[13]: 1434743731877000000

In [14]: (pd.Timestamp('2015-06-19 19:55:15.877000')+pd.Timedelta('1us')).value
Out[14]: 1434743715877001000


This comment has been minimized.


jorisvandenbossche commented Feb 15, 2018

Copying from #19680

It happens in this function:

In [126]: pd._libs.tslibs.timedeltas.cast_from_unit(1.5e-6, 's')
Out[126]: 2000

because we round at 6 decimals:

elif unit == 's':
m = 1000000000L
p = 6

frac = round(frac, p)

Not fully sure why we choose 6 decimals to be allowed, and not 9 in case of 's' (and 6 in case of 'ms', 3 for 'us', ..)


This comment has been minimized.


Sup3rGeo commented Mar 26, 2018

Isn't this the same as #12690?


This comment has been minimized.


jorisvandenbossche commented Mar 26, 2018

Indeed, will close the other in favor of this one. Thanks for noticing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment