Inconsistent behaviour in Timestamp.round · Issue #22591 · pandas-dev/pandas (original) (raw)
Code Sample
import pandas as pd a = pd.to_datetime('2000-01-01 0:0:0.124999360') b = pd.to_datetime('2018-01-01 0:0:0.124999360') a.round('us') Timestamp('2000-01-01 00:00:00.124999') b.round('us') Timestamp('2018-01-01 00:00:00.125000')
Problem description
According to the standard definition of rounding to a multiple b.round('us')
in the example above gives the wrong answer.
I suspect that there is loss of precision due to a floating point conversion.
>>> round(a.value / 1e9, 6)
946684800.124999
>>> round(b.value / 1e9, 6)
1514764800.125
Expected Output
>>> b.round('us')
Timestamp('2018-01-01 00:00:00.124999')
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.0.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.4
pytest: None
pip: 18.0
setuptools: 39.0.1
Cython: None
numpy: 1.15.1
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None