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

Comments

Projects
None yet
2 participants
@TomAugspurger
Copy link
Contributor

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

This comment has been minimized.

Copy link
Member

commented Aug 17, 2018

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

@TomAugspurger

This comment has been minimized.

Copy link
Contributor Author

commented Aug 17, 2018

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

This comment has been minimized.

Copy link
Member

commented Aug 17, 2018

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

jreback added a commit that referenced this issue Sep 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.