Skip to content

Commit 70de129

Browse files
committed
Merge branch 'general-shift-4867-panel' of https://github.com/dalejung/pandas into dalejung-general-shift-4867-panel
Conflicts: doc/source/release.rst doc/source/v0.14.0.txt
2 parents 772b13a + 81b67c4 commit 70de129

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ API Changes
152152

153153
- all offset operations now return ``Timestamp`` types (rather than datetime), Business/Week frequencies were incorrect (:issue:`4069`)
154154
- ``Series.iteritems()`` is now lazy (returns an iterator rather than a list). This was the documented behavior prior to 0.14. (:issue:`6760`)
155+
- ``Panel.shift`` now uses ``NDFrame.shift``. It no longer drops the ``nan`` data and retains its original shape. (:issue:`4867`)
155156

156157
Deprecations
157158
~~~~~~~~~~~~

doc/source/v0.14.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ API changes
197197
covs[df.index[-1]]
198198

199199
- ``Series.iteritems()`` is now lazy (returns an iterator rather than a list). This was the documented behavior prior to 0.14. (:issue:`6760`)
200+
- ``Panel.shift`` now uses ``NDFrame.shift``. It no longer drops the ``nan`` data and retains its original shape. (:issue:`4867`)
200201

201202

202203
MultiIndexing Using Slicers

pandas/core/panel.py

+3-26
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,7 @@ def count(self, axis='major'):
11161116

11171117
def shift(self, lags, freq=None, axis='major'):
11181118
"""
1119-
Shift major or minor axis by specified number of leads/lags. Drops
1120-
periods right now compared with DataFrame.shift
1119+
Shift major or minor axis by specified number of leads/lags.
11211120
11221121
Parameters
11231122
----------
@@ -1128,35 +1127,13 @@ def shift(self, lags, freq=None, axis='major'):
11281127
-------
11291128
shifted : Panel
11301129
"""
1131-
values = self.values
1132-
items = self.items
1133-
major_axis = self.major_axis
1134-
minor_axis = self.minor_axis
1135-
11361130
if freq:
11371131
return self.tshift(lags, freq, axis=axis)
11381132

1139-
if lags > 0:
1140-
vslicer = slice(None, -lags)
1141-
islicer = slice(lags, None)
1142-
elif lags == 0:
1143-
vslicer = islicer = slice(None)
1144-
else:
1145-
vslicer = slice(-lags, None)
1146-
islicer = slice(None, lags)
1147-
1148-
axis = self._get_axis_name(axis)
1149-
if axis == 'major_axis':
1150-
values = values[:, vslicer, :]
1151-
major_axis = major_axis[islicer]
1152-
elif axis == 'minor_axis':
1153-
values = values[:, :, vslicer]
1154-
minor_axis = minor_axis[islicer]
1155-
else:
1133+
if axis == 'items':
11561134
raise ValueError('Invalid axis')
11571135

1158-
return self._constructor(values, items=items, major_axis=major_axis,
1159-
minor_axis=minor_axis)
1136+
return super(Panel, self).shift(lags, freq=freq, axis=axis)
11601137

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

pandas/tests/test_panel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ def test_shift(self):
16421642

16431643
# negative numbers, #2164
16441644
result = self.panel.shift(-1)
1645-
expected = Panel(dict((i, f.shift(-1)[:-1])
1645+
expected = Panel(dict((i, f.shift(-1))
16461646
for i, f in compat.iteritems(self.panel)))
16471647
assert_panel_equal(result, expected)
16481648

vb_suite/panel_methods.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from vbench.api import Benchmark
2+
from datetime import datetime
3+
4+
common_setup = """from pandas_vb_common import *
5+
"""
6+
7+
#----------------------------------------------------------------------
8+
# shift
9+
10+
setup = common_setup + """
11+
index = date_range(start="2000", freq="D", periods=1000)
12+
panel = Panel(np.random.randn(100, len(index), 1000))
13+
"""
14+
15+
panel_shift = Benchmark('panel.shift(1)', setup,
16+
start_date=datetime(2012, 1, 12))
17+
18+
panel_shift_minor = Benchmark('panel.shift(1, axis=minor)', setup,
19+
start_date=datetime(2012, 1, 12))

vb_suite/suite.py

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'panel_ctor',
1919
'packers',
2020
'parser_vb',
21+
'panel_methods',
2122
'plotting',
2223
'reindex',
2324
'replace',

0 commit comments

Comments
 (0)