Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: passing TDA and wrong freq to TimedeltaIndex #31268

Merged
merged 4 commits into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,6 @@ def __new__(
"represent unambiguous timedelta values durations."
)

if isinstance(data, TimedeltaArray):
if copy:
data = data.copy()
return cls._simple_new(data, name=name, freq=freq)

if isinstance(data, TimedeltaIndex) and freq is None and name is None:
if copy:
return data.copy()
else:
return data._shallow_copy()

# - Cases checked above all return/raise before reaching here - #

tdarr = TimedeltaArray._from_sequence(
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexes/timedeltas/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down