Skip to content

Commit 839e7f1

Browse files
jbrockmendeljreback
authored andcommitted
BUG: passing TDA and wrong freq to TimedeltaIndex (#31268)
1 parent 9a211aa commit 839e7f1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pandas/core/indexes/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __new__(
163163
"represent unambiguous timedelta values durations."
164164
)
165165

166-
if isinstance(data, TimedeltaArray):
166+
if isinstance(data, TimedeltaArray) and freq is None:
167167
if copy:
168168
data = data.copy()
169169
return cls._simple_new(data, name=name, freq=freq)

pandas/tests/indexes/timedeltas/test_constructors.py

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ def test_infer_from_tdi_mismatch(self):
4747
# GH#23789
4848
TimedeltaArray(tdi, freq="D")
4949

50+
with pytest.raises(ValueError, match=msg):
51+
TimedeltaIndex(tdi._data, freq="D")
52+
53+
with pytest.raises(ValueError, match=msg):
54+
TimedeltaArray(tdi._data, freq="D")
55+
5056
def test_dt64_data_invalid(self):
5157
# GH#23539
5258
# passing tz-aware DatetimeIndex raises, naive or ndarray[datetime64]

0 commit comments

Comments
 (0)