-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
API/DEPR: 'periods' argument instead of 'n' for DatetimeIndex.shift() #22697
Conversation
Hello @arminv! Thanks for updating the PR.
Comment last updated on September 15, 2018 at 18:58 Hours UTC |
pandas/core/arrays/datetimelike.py
Outdated
@@ -521,40 +521,52 @@ def _addsub_offset_array(self, other, op): | |||
kwargs['freq'] = 'infer' | |||
return type(self)(res_values, **kwargs) | |||
|
|||
def shift(self, n, freq=None): | |||
def shift(self, periods, freq=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to deprecate periods. Your change would break people doing .shift(n=1)
.
This could be somewhat tricky to do... I think you may have to make the signature *args, **kwargs
, and manually do the parsing
shift(1)
: no warningshift(n=1)
: warningshift(periods=1)
: no warning
lmk if you need help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomAugspurger Thanks. I started parsing manually but couldn't make some tests pass. Then I realized there is a decorator in pandas/pandas/util/_decorators.py
that I could use for deprecating n
. Lmk if there is anything else to be done.
Codecov Report
@@ Coverage Diff @@
## master #22697 +/- ##
==========================================
+ Coverage 92.17% 92.17% +<.01%
==========================================
Files 169 169
Lines 50778 50780 +2
==========================================
+ Hits 46807 46809 +2
Misses 3971 3971
Continue to review full report at Codecov.
|
-------- | ||
Index.shift : Shift values of Index. | ||
DatetimeIndex.shift : Shift values of DatetimeIndex. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback I also added Index.shift
here.
tm.assert_index_equal(idx.shift(periods=0), idx) | ||
tm.assert_index_equal(idx.shift(0), idx) | ||
with tm.assert_produces_warning(FutureWarning, | ||
check_stacklevel=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this to true? If the test fails, you may need to increase the stacklevel 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomAugspurger done, test passed too.
Thanks! |
git diff upstream/master -u -- "*.py" | flake8 --diff
In order to be consistent with
Index.shift
&Series.shift
,n
argument was deprecated in favor ofperiods
.