Skip to content

Calling shift(n != 0) on an empty DatetimeIndex raises an IndexError #14811

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

Closed
chazmo03 opened this issue Dec 6, 2016 · 2 comments · Fixed by #36691
Closed

Calling shift(n != 0) on an empty DatetimeIndex raises an IndexError #14811

chazmo03 opened this issue Dec 6, 2016 · 2 comments · Fixed by #36691
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@chazmo03
Copy link

chazmo03 commented Dec 6, 2016

Calling shift(0) on an empty DatetimeIndex seems to return an empty index, but calling shift(n) with a non-zero n raises an IndexError. I would expect this to return an empty index.

# this works
pd.date_range(start='20161021', end='20161021', freq='BM').shift(0)

# this raises
pd.date_range(start='20161021', end='20161021', freq='BM').shift(1)
# IndexError: index 0 is out of bounds for axis 0 with size 0

pd.__version__
# u'0.18.1'
@chris-b1
Copy link
Contributor

chris-b1 commented Dec 6, 2016

This feels like odd behavior to be relying on, but would be consistent with Series

In [20]: s = pd.Series([])

In [21]: s.shift(0)
Out[21]: Series([], dtype: float64)

In [22]: s.shift(-1)
Out[22]: Series([], dtype: float64)

@chris-b1 chris-b1 added API Design Datetime Datetime data dtype labels Dec 6, 2016
@chris-b1
Copy link
Contributor

chris-b1 commented Dec 6, 2016

xref #13026 - seems to have been a little discussion about this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants