diff --git a/doc/source/v0.15.0.txt b/doc/source/v0.15.0.txt index 4bd55b2172013..b3ee0980635e3 100644 --- a/doc/source/v0.15.0.txt +++ b/doc/source/v0.15.0.txt @@ -389,7 +389,7 @@ Enhancements - +- Bug in ``DataFrame.shift`` where empty columns would throw ``ZeroDivisionError`` on numpy 1.7 (:issue:`8019`) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index f3b8a54034d56..58f98b4ee21e6 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -817,7 +817,10 @@ def shift(self, periods, axis=0): if f_ordered: new_values = new_values.T axis = new_values.ndim - axis - 1 - new_values = np.roll(new_values, periods, axis=axis) + + if np.prod(new_values.shape): + new_values = np.roll(new_values, periods, axis=axis) + axis_indexer = [ slice(None) ] * self.ndim if periods > 0: axis_indexer[axis] = slice(None,periods) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index d1e6a2bf59303..b4e548dd5b964 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -9610,6 +9610,13 @@ def test_shift_bool(self): columns=['high', 'low']) assert_frame_equal(rs, xp) + def test_shift_empty(self): + # Regression test for #8019 + df = DataFrame({'foo': []}) + rs = df.shift(-1) + + assert_frame_equal(df, rs) + def test_tshift(self): # PeriodIndex ps = tm.makePeriodFrame()