Skip to content

Rounding errors when parsing timedeltas #12690

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

Closed
belteshassar opened this issue Mar 22, 2016 · 2 comments
Closed

Rounding errors when parsing timedeltas #12690

belteshassar opened this issue Mar 22, 2016 · 2 comments
Labels
Bug Timedelta Timedelta data type

Comments

@belteshassar
Copy link

Found this while working on #12136.

Rounding errors occur for timedeltas initialized using fractional microsecond values:

>>> pd.Timedelta('12.312us') == pd.Timedelta(12312)
False
>>> pd.Timedelta(12.312, unit='us') == pd.Timedelta(12312)
False
>>> pd.Timedelta('12.312us') == pd.Timedelta(12311)
True

Additionally, precision is lost when initializing timedeltas with fractional millisecond (and probably second) values:

>>> pd.Timedelta(0.012312, unit='ms') == pd.Timedelta(12311)
False
>>> pd.Timedelta(0.012311, unit='ms') == pd.Timedelta(12311)
False
>>> pd.Timedelta(0.012311, unit='ms') == pd.Timedelta(12000)
True

I believe the problem is here: https://github.com/pydata/pandas/blob/288059adfb751d52be57e444198198518d256c05/pandas/tslib.pyx#L3399
bumping up the values of p should probably solve this.

output of pd.show_versions()

commit: None
python: 2.7.11.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0+unknown
nose: 1.3.7
pip: 8.1.0
setuptools: 20.2.2
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.17.0
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: 1.3.5
patsy: 0.4.0
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.6
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: 1.0.0
xlsxwriter: 0.8.4
lxml: 3.5.0
bs4: 4.3.2
html5lib: 0.999
httplib2: None
apiclient: None
sqlalchemy: 1.0.12
pymysql: 0.6.7.None
psycopg2: None
jinja2: 2.8
boto: None

@jreback
Copy link
Contributor

jreback commented Mar 22, 2016

you can try that, though might break other things.

@jreback jreback added this to the 0.18.1 milestone Mar 22, 2016
@jreback jreback modified the milestones: 0.18.2, 0.18.1 Apr 26, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: Next Major Release, 0.19.0 Aug 21, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: Next Major Release, No action Mar 26, 2018
@jorisvandenbossche
Copy link
Member

Closing in favor of #14156

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

No branches or pull requests

3 participants