Skip to content

Timestamp.floor() rounds up when a few nanoseconds before a round time #24225

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
frexvahi opened this issue Dec 11, 2018 · 2 comments
Closed
Labels
Duplicate Report Duplicate issue or pull request

Comments

@frexvahi
Copy link
Contributor

Code Sample, a copy-pastable example if possible

>>> pd.Timestamp('2001-02-03 04:05:06.99999999').floor('1s')
Timestamp('2001-02-03 04:05:07')

>>> pd.Timestamp('2004-05-06 07:08:59.9999999').floor('1min')
Timestamp('2004-05-06 07:09:00')

Problem description

For times very close to but below a round second, pd.Timestamp.floor() will round up instead of down. The threshold for where this happens varies from second to second but seems to be between 50 and 200 nanoseconds (i.e. .9999998 will floor() correctly, .99999995 will floor() to the next second upwards).

Expected Output

Timestamp('2001-02-03 04:05:06')
Timestamp('2004-05-06 07:08:00')

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-42-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.23.4
pytest: 4.0.1
pip: 18.1
setuptools: 40.6.2
Cython: 0.29
numpy: 1.15.4
scipy: 1.0.0
pyarrow: None
xarray: 0.11.0
IPython: 7.2.0
sphinx: 1.8.2
patsy: 0.5.0
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: 2.5.11
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.2
lxml: 4.2.5
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.14
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@chris-b1
Copy link
Contributor

Thanks for the report - this looks to be fixed in master - probably should add some confirming tests

In [2]: ts = pd.Timestamp('2001-02-03 04:05:06.99999999')

In [3]: ts.floor('1s')
Out[3]: Timestamp('2001-02-03 04:05:06')

In [4]: pd.Timestamp('2004-05-06 07:08:59.9999999').floor('1min')
Out[4]: Timestamp('2004-05-06 07:08:00')

@chris-b1
Copy link
Contributor

Fixed by #22802 (test coverage is good), duplicate of #22591

@chris-b1 chris-b1 added the Duplicate Report Duplicate issue or pull request label Dec 11, 2018
@chris-b1 chris-b1 added this to the No action milestone Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants