Skip to content
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

Inconsistent keyword argument name for the 'periods' in pandas.Index.shift for a DatetimeIndex #22458

Closed
SaberStrat opened this issue Aug 22, 2018 · 3 comments · Fixed by #22697 or #22912
Labels
API Design Datetime Datetime data dtype Deprecate Functionality to remove in pandas
Milestone

Comments

@SaberStrat
Copy link

SaberStrat commented Aug 22, 2018

The actual implementation of pandas.Index.shift for a datetime-like index takes a differently named parameter for the number of shifts than the base method.

It should be named periods, which would also be consistent with the pandas.DataFrame.shift or pandas.Series.shift methods. But for a DatetimeIndex it's n.

See:
https://github.com/pandas-dev/pandas/blob/v0.23.4/pandas/core/indexes/base.py#L2586
vs.
https://github.com/pandas-dev/pandas/blob/v0.23.4/pandas/core/indexes/datetimelike.py#L1021

With a DatetimeIndex, following the documentation leads to a

TypeError: shift() got an unexpected keyword argument 'periods'

If this is somehow intended, then it should be stated so in the docstring for pandas.Index.shift.

pandas version is 0.23.4

@TomAugspurger
Copy link
Contributor

They probably used to be separate classes, and then were merged. We could deprecate n and replace it with periods.

@TomAugspurger
Copy link
Contributor

@arminv do you have any interest in doing the same for PeriodIndex? I think we should be consistent everywhere if possible.

def shift(self, n):

@TomAugspurger TomAugspurger reopened this Sep 27, 2018
@arminv
Copy link
Contributor

arminv commented Sep 27, 2018

@TomAugspurger yeah sure! I’ll start working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype Deprecate Functionality to remove in pandas
Projects
None yet
5 participants