Skip to content

Commit ac9b247

Browse files
author
Tom Augspurger
committed
Merge pull request #6928 from TomAugspurger/panel_shift_kwarg
API/DEPR: Match Panel.shift()'s signature to generic
2 parents 6c36769 + 5524c3c commit ac9b247

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

doc/source/release.rst

+5
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ Deprecations
201201
- Indexers will warn ``FutureWarning`` when used with a scalar indexer and
202202
a non-floating point Index (:issue:`4892`)
203203

204+
- :meth:`Panel.shift` now has a function signature that matches :meth:`DataFrame.shift`.
205+
The old positional argument ``lags`` has been changed to a keyword argument
206+
``periods`` with a default value of 1. A ``FutureWarning`` is raised if the
207+
old argument ``lags`` is used by name. (:issue:`6910`)
208+
204209
Prior Version Deprecations/Changes
205210
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
206211

doc/source/v0.14.0.txt

+5
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ Deprecations
416416
In [4]: Series(1,np.arange(5.))[3.0]
417417
Out[4]: 1
418418

419+
- :meth:`Panel.shift` now has a function signature that matches :meth:`DataFrame.shift`.
420+
The old positional argument ``lags`` has been changed to a keyword argument
421+
``periods`` with a default value of 1. A ``FutureWarning`` is raised if the
422+
old argument ``lags`` is used by name. (:issue:`6910`)
423+
419424
.. _whatsnew_0140.enhancements:
420425

421426
Enhancements

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3489,7 +3489,8 @@ def pct_change(self, periods=1, fill_method='pad', limit=None, freq=None,
34893489
else:
34903490
data = self.fillna(method=fill_method, limit=limit)
34913491

3492-
rs = data.div(data.shift(periods, freq=freq, axis=axis, **kwds)) - 1
3492+
rs = (data.div(data.shift(periods=periods, freq=freq,
3493+
axis=axis, **kwds)) - 1)
34933494
if freq is None:
34943495
mask = com.isnull(_values_from_object(self))
34953496
np.putmask(rs.values, mask, np.nan)

pandas/core/panel.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from pandas.core.generic import NDFrame, _shared_docs
2323
from pandas.tools.util import cartesian_product
2424
from pandas import compat
25-
from pandas.util.decorators import deprecate, Appender, Substitution
25+
from pandas.util.decorators import (deprecate, Appender, Substitution,
26+
deprecate_kwarg)
2627
import pandas.core.common as com
2728
import pandas.core.ops as ops
2829
import pandas.core.nanops as nanops
@@ -1150,7 +1151,8 @@ def count(self, axis='major'):
11501151

11511152
return self._wrap_result(result, axis)
11521153

1153-
def shift(self, lags, freq=None, axis='major'):
1154+
@deprecate_kwarg(old_arg_name='lags', new_arg_name='periods')
1155+
def shift(self, periods=1, freq=None, axis='major'):
11541156
"""
11551157
Shift major or minor axis by specified number of leads/lags.
11561158
@@ -1164,12 +1166,12 @@ def shift(self, lags, freq=None, axis='major'):
11641166
shifted : Panel
11651167
"""
11661168
if freq:
1167-
return self.tshift(lags, freq, axis=axis)
1169+
return self.tshift(periods, freq, axis=axis)
11681170

11691171
if axis == 'items':
11701172
raise ValueError('Invalid axis')
11711173

1172-
return super(Panel, self).shift(lags, freq=freq, axis=axis)
1174+
return super(Panel, self).shift(periods, freq=freq, axis=axis)
11731175

11741176
def tshift(self, periods=1, freq=None, axis='major', **kwds):
11751177
return super(Panel, self).tshift(periods, freq, axis, **kwds)

pandas/tests/test_panel.py

+14
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,20 @@ def setUp(self):
824824
self.panel.minor_axis.name = None
825825
self.panel.items.name = None
826826

827+
def test_panel_warnings(self):
828+
with tm.assert_produces_warning(FutureWarning):
829+
shifted1 = self.panel.shift(lags=1)
830+
831+
with tm.assert_produces_warning(False):
832+
shifted2 = self.panel.shift(periods=1)
833+
834+
tm.assert_panel_equal(shifted1, shifted2)
835+
836+
with tm.assert_produces_warning(False):
837+
shifted3 = self.panel.shift()
838+
839+
tm.assert_panel_equal(shifted1, shifted3)
840+
827841
def test_constructor(self):
828842
# with BlockManager
829843
wp = Panel(self.panel._data)

0 commit comments

Comments
 (0)