10000 DOC: updating docstring of Index.shift by DataOmbudsman · Pull Request #19996 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DOC: updating docstring of Index.shift #19996

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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Removing See Also section, adding Returns and Examples sections
  • Loading branch information
Arpad Fulop committed Mar 6, 2018
commit 1523ba8ec245f98f0a1df9c24df988d133ce1c03
35 changes: 26 additions & 9 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,20 +2223,37 @@ def shift(self, periods=1, freq=None):
can be positive or negative (default is 1).
freq : pandas.DateOffset, pandas.Timedelta or string
Frequency increment to shift by (default is None).
Offset aliases are valid strings, e.g., 'EOM'.
If None, the index is shifted by its own `freq` attribute.
Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.

See Also
Returns
-------
pandas.Index
shifted index

Examples
--------
DatetimeIndex.shift : an implementation of shift.
PeriodIndex.shift : an implementation of shift.
TimedeltaIndex.shift : an implementation of shift.
>>> month_starts = pd.date_range('1/1/2011', periods=5, freq='MS')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show the output here? (so it is easier to compare the result of the shift with the original)

Shift by 10 days.

>>> month_starts.shift(10, freq='D')
DatetimeIndex(['2011-01-11', '2011-02-11', '2011-03-11', '2011-04-11',
'2011-05-11'],
dtype='datetime64[ns]', freq=None)

The default value of `freq` is the `freq` attribute of the index;
in this example it is 'MS' (month start).

>>> month_starts.shift(10)
DatetimeIndex(['2011-11-01', '2011-12-01', '2012-01-01', '2012-02-01',
'2012-03-01'],
dtype='datetime64[ns]', freq='MS')

Notes
-----
Must be overridden in child classes.
h
Implemented in datetime-like index classes,
e.g., DatetimeIndex, PeriodIndex and TimedeltaIndex.
This method is only implemented for datetime-like index classes,
i.e., DatetimeIndex, PeriodIndex and TimedeltaIndex.
"""
raise NotImplementedError("Not supported for type %s" %
type(self).__name__)
Expand Down
0