Skip to content

Make Series.shift always a copy? #22397

Closed
@TomAugspurger

Description

@TomAugspurger

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions