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

Make Series.shift always a copy? #22397

Closed
TomAugspurger opened this issue Aug 17, 2018 · 3 comments · Fixed by #22517
Closed

Make Series.shift always a copy? #22397

TomAugspurger opened this issue Aug 17, 2018 · 3 comments · Fixed by #22517
Milestone

Comments

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Aug 17, 2018

Right now, Series.shift(0) will just return the series. Shifting for all other periods induces a copy:

In [1]: import pandas as pd

In [2]: a = pd.Series([1, 2])

In [3]: a.shift(1) is a
Out[3]: False

In [4]: a.shift(0) is a
Out[4]: True

Should we defensively copy on 0 as well, for a consistent user experience?

pandas/pandas/core/generic.py

Lines 8084 to 8086 in e669fae

def shift(self, periods=1, freq=None, axis=0):
if periods == 0:
return self

@WillAyd
Copy link
Member

WillAyd commented Aug 17, 2018

What if we disallowed shifting by zero? Seems like a useless argument for this function anyway

@TomAugspurger
Copy link
Contributor Author

Special casing edge cases seems to always end up biting us in the end. Since a length-0 shift is well-defined, I'd prefer to just allow it.

@WillAyd
Copy link
Member

WillAyd commented Aug 17, 2018

Fair enough - in that case I'm +1 on always copy

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

Successfully merging a pull request may close this issue.

2 participants