Skip to content

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

Closed
@frexvahi

Description

@frexvahi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions