diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index d0a31b68250ad..e78714487f01e 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -163,7 +163,7 @@ def __new__( "represent unambiguous timedelta values durations." ) - if isinstance(data, TimedeltaArray): + if isinstance(data, TimedeltaArray) and freq is None: if copy: data = data.copy() return cls._simple_new(data, name=name, freq=freq) diff --git a/pandas/tests/indexes/timedeltas/test_constructors.py b/pandas/tests/indexes/timedeltas/test_constructors.py index 39abbf59d1e56..32e6821e87f05 100644 --- a/pandas/tests/indexes/timedeltas/test_constructors.py +++ b/pandas/tests/indexes/timedeltas/test_constructors.py @@ -47,6 +47,12 @@ def test_infer_from_tdi_mismatch(self): # GH#23789 TimedeltaArray(tdi, freq="D") + with pytest.raises(ValueError, match=msg): + TimedeltaIndex(tdi._data, freq="D") + + with pytest.raises(ValueError, match=msg): + TimedeltaArray(tdi._data, freq="D") + def test_dt64_data_invalid(self): # GH#23539 # passing tz-aware DatetimeIndex raises, naive or ndarray[datetime64]