Skip to content
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
31 changes: 25 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2211,13 +2211,32 @@ def sortlevel(self, level=None, ascending=True, sort_remaining=None):
return self.sort_values(return_indexer=True, ascending=ascending)

def shift(self, periods=1, freq=None):
"""
Shift Index containing datetime objects by input number of periods and
DateOffset
"""Shift index by desired number of time frequency increments.

Returns
-------
shifted : Index
This method is for shifting the values of datetime-like indexes
by a specified time increment a given number of times.

Parameters
----------
periods : int
Number of periods (or increments) to shift by,
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'.
Copy link
Member

Choose a reason for hiding this comment

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

We should explain here what the default of None means.


See Also
--------
DatetimeIndex.shift : an implementation of shift.
PeriodIndex.shift : an implementation of shift.
TimedeltaIndex.shift : an implementation of shift.
Copy link
Member

Choose a reason for hiding this comment

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

In principle it is good to add this, but since those are not included in the API docs online, the links will not work, and since this docstring is also used for those referenced methods, it is maybe not needed to include those links (mentioning in the notes that those are implemented will be OK I think)


Notes
-----
Must be overridden in child classes.
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed here (not relevant information for the user, but only for the developer), although could keep it as a normal comment (# .. ) after the docstring to clarify this.

I would maybe mention in the Notes section that "This method is only implemented for DatetimeIndex, PeriodIndex and TimedeltaIndex"

h
Implemented in datetime-like index classes,
e.g., DatetimeIndex, PeriodIndex and TimedeltaIndex.
"""
raise NotImplementedError("Not supported for type %s" %
type(self).__name__)
Expand Down