Skip to content

BUG: timedelta.round fails to round to nearest day #57781

@jbogaardt

Description

@jbogaardt

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

It seems like timedelta rounding broke with the 2.2.0 release or the naming convention for rounding frequency is not properly documented.

Issue Description

Under pandas>=2.2.0, I cannot get any rounding to occur whether I use 'D', 'd', 'day', or 'days':

>>> import pandas as pd
>>> print(pd.__version__)
2.2.1
>>> pd.Series([
...     pd.Timedelta('1 days 23:18:00'),
...     pd.Timedelta('2 days 07:00:00')]).round('d')
0   1 days 23:18:00
1   2 days 07:00:00
dtype: timedelta64[ns]

Expected Behavior

Before 2.2.0 timedeltas rounded to the nearest day appropriately:

>>> import pandas as pd
>>> print(pd.__version__)
2.1.4
dtype: timedelta64[ns]
>>> pd.Series([
...     pd.Timedelta('1 days 23:18:00'),
...     pd.Timedelta('2 days 07:00:00')]).round('d')
0   2 days
1   2 days
dtype: timedelta64[ns]

Installed Versions

INSTALLED VERSIONS

commit : bdc79c1
python : 3.11.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 126 Stepping 5, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252

pandas : 2.2.1
numpy : 1.24.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.3
Cython : None
pytest : 7.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.0
numba : 0.58.0
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 14.0.1
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team memberTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions