Skip to content

Commit

Permalink
DOC/CLN: docs fixes for Series.shift and DataFrame.shift
Browse files Browse the repository at this point in the history
  • Loading branch information
mortada committed May 8, 2015
1 parent e686387 commit 45371a0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
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

0 comments on commit 45371a0

Please sign in to comment.