Skip to content

DOC/CLN: docs fixes for Series.shift and DataFrame.shift #10082

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 1 commit into from
May 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/source/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,7 @@ Shifting / lagging

One may want to *shift* or *lag* the values in a TimeSeries back and forward in
time. The method for this is ``shift``, which is available on all of the pandas
objects. In DataFrame, ``shift`` will currently only shift along the ``index``
and in Panel along the ``major_axis``.
objects.

.. ipython:: python

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,11 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
limit=limit, downcast=downcast,
**kwargs)

@Appender(_shared_docs['shift'] % _shared_doc_kwargs)
def shift(self, periods=1, freq=None, axis=0, **kwargs):
return super(DataFrame, self).shift(periods=periods, freq=freq,
axis=axis, **kwargs)

def set_index(self, keys, drop=True, append=False, inplace=False,
verify_integrity=False):
"""
Expand Down
10 changes: 6 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3584,8 +3584,7 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
return self.where(~cond, other=other, inplace=inplace, axis=axis,
level=level, try_cast=try_cast, raise_on_error=raise_on_error)

def shift(self, periods=1, freq=None, axis=0, **kwargs):
"""
_shared_docs['shift'] = ("""
Shift index by desired number of periods with an optional time freq

Parameters
Expand All @@ -3595,6 +3594,7 @@ def shift(self, periods=1, freq=None, axis=0, **kwargs):
freq : DateOffset, timedelta, or time rule string, optional
Increment to use from datetools module or time rule (e.g. 'EOM').
See Notes.
axis : %(axes_single_arg)s

Notes
-----
Expand All @@ -3604,8 +3604,10 @@ def shift(self, periods=1, freq=None, axis=0, **kwargs):

Returns
-------
shifted : same type as caller
"""
shifted : %(klass)s
""")
@Appender(_shared_docs['shift'] % _shared_doc_kwargs)
def shift(self, periods=1, freq=None, axis=0, **kwargs):
if periods == 0:
return self

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,11 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
limit=limit, downcast=downcast,
**kwargs)

@Appender(generic._shared_docs['shift'] % _shared_doc_kwargs)
def shift(self, periods=1, freq=None, axis=0, **kwargs):
return super(Series, self).shift(periods=periods, freq=freq,
axis=axis, **kwargs)

def reindex_axis(self, labels, axis=0, **kwargs):
""" for compatibility with higher dims """
if axis != 0:
Expand Down