Skip to content

Commit 7554c87

Browse files
author
TomAugspurger
committed
API: align Panel.shift API with generic
1 parent 6c36769 commit 7554c87

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
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/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)