Skip to content

BUG: In main, TimedeltaIndex.shift() requires freq in the index, but it may not be available because it was computed #62094

@Dr-Irv

Description

@Dr-Irv

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

import pandas as pd
ind = pd.date_range("1/1/2021", "1/5/2021") - pd.Timestamp("1/3/2019")
ind.shift(1)

Issue Description

This only occurs on main. NOT a current bug in pandas.

Gives error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Code\pandas_dev\pandas\pandas\core\indexes\datetimelike.py", line 512, in shift
    raise NullFrequencyError("Cannot shift with no freq")
pandas.errors.NullFrequencyError: Cannot shift with no freq

The above code works fine with pandas 2.3.

Expected Behavior

No error. A user doing a calculation that produces a TimedeltaIndex can't be expected to set the freq of the index.

I think was introduced by @jbrockmendel in #61985

Installed Versions

INSTALLED VERSIONS

commit : bb10b27
python : 3.11.13
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.26100
machine : AMD64
processor : Intel64 Family 6 Model 183 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 3.0.0.dev0+2306.gbb10b27dea.dirty
numpy : 2.2.6
dateutil : 2.9.0.post0
pip : 25.2
Cython : 3.1.2
sphinx : 8.2.3
IPython : 9.4.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.4
bottleneck : 1.5.0
fastparquet : 2024.11.0
fsspec : 2025.7.0
html5lib : 1.1
hypothesis : 6.137.3
gcsfs : 2025.7.0
jinja2 : 3.1.6
lxml.etree : 6.0.0
matplotlib : 3.10.5
numba : 0.61.2
numexpr : 2.10.2
odfpy : None
openpyxl : 3.1.5
psycopg2 : 2.9.10
pymysql : 1.4.6
pyarrow : 19.0.1
pyiceberg : 0.9.1
pyreadstat : 1.3.0
pytest : 8.4.1
python-calamine : None
pytz : 2025.2
pyxlsb : 1.0.10
s3fs : 2025.7.0
scipy : 1.16.1
sqlalchemy : 2.0.43
tables : 3.10.2
tabulate : 0.9.0
xarray : 2025.7.1
xlrd : 2.0.1
xlsxwriter : 3.2.5
zstandard : 0.23.0
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BlockerBlocking issue or pull request for an upcoming releaseBugTimedeltaTimedelta data typegood first issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions