Skip to content

BUG: TDI.insert with empty TDI raising IndexError #30757

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

Merged
merged 10 commits into from
Jan 9, 2020
9 changes: 9 additions & 0 deletions pandas/tests/indexes/timedeltas/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ def test_take_fill_value(self):


class TestTimedeltaIndex:
def test_insert_empty(self):
# Corner case inserting with length zero doesnt raise IndexError
idx = timedelta_range("1 Day", periods=3)
td = idx[0]

idx[:0].insert(0, td)
idx[:0].insert(1, td)
idx[:0].insert(-1, td)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe worth comparing the results

def test_insert(self):

idx = TimedeltaIndex(["4day", "1day", "2day"], name="idx")
Expand Down