Skip to content

Commit

Permalink
Merge branch 'general-shift-4867-panel' of https://github.com/dalejun…
Browse files Browse the repository at this point in the history
…g/pandas into dalejung-general-shift-4867-panel

Conflicts:
	doc/source/release.rst
	doc/source/v0.14.0.txt
  • Loading branch information
jreback committed Apr 1, 2014
2 parents 772b13a + 81b67c4 commit 70de129
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ API Changes

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

Deprecations
~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions doc/source/v0.14.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ API changes
covs[df.index[-1]]

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


MultiIndexing Using Slicers
Expand Down
29 changes: 3 additions & 26 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1116,8 +1116,7 @@ def count(self, axis='major'):

def shift(self, lags, freq=None, axis='major'):
"""
Shift major or minor axis by specified number of leads/lags. Drops
periods right now compared with DataFrame.shift
Shift major or minor axis by specified number of leads/lags.
Parameters
----------
Expand All @@ -1128,35 +1127,13 @@ def shift(self, lags, freq=None, axis='major'):
-------
shifted : Panel
"""
values = self.values
items = self.items
major_axis = self.major_axis
minor_axis = self.minor_axis

if freq:
return self.tshift(lags, freq, axis=axis)

if lags > 0:
vslicer = slice(None, -lags)
islicer = slice(lags, None)
elif lags == 0:
vslicer = islicer = slice(None)
else:
vslicer = slice(-lags, None)
islicer = slice(None, lags)

axis = self._get_axis_name(axis)
if axis == 'major_axis':
values = values[:, vslicer, :]
major_axis = major_axis[islicer]
elif axis == 'minor_axis':
values = values[:, :, vslicer]
minor_axis = minor_axis[islicer]
else:
if axis == 'items':
raise ValueError('Invalid axis')

return self._constructor(values, items=items, major_axis=major_axis,
minor_axis=minor_axis)
return super(Panel, self).shift(lags, freq=freq, axis=axis)

def tshift(self, periods=1, freq=None, axis='major', **kwds):
return super(Panel, self).tshift(periods, freq, axis, **kwds)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ def test_shift(self):

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

Expand Down
19 changes: 19 additions & 0 deletions vb_suite/panel_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from vbench.api import Benchmark
from datetime import datetime

common_setup = """from pandas_vb_common import *
"""

#----------------------------------------------------------------------
# shift

setup = common_setup + """
index = date_range(start="2000", freq="D", periods=1000)
panel = Panel(np.random.randn(100, len(index), 1000))
"""

panel_shift = Benchmark('panel.shift(1)', setup,
start_date=datetime(2012, 1, 12))

panel_shift_minor = Benchmark('panel.shift(1, axis=minor)', setup,
start_date=datetime(2012, 1, 12))
1 change: 1 addition & 0 deletions vb_suite/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'panel_ctor',
'packers',
'parser_vb',
'panel_methods',
'plotting',
'reindex',
'replace',
Expand Down

0 comments on commit 70de129

Please sign in to comment.