Skip to content

BUG: Don't call np.roll on empty arrays. #8041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Enhancements




- Bug in ``DataFrame.shift`` where empty columns would throw ``ZeroDivisionError`` on numpy 1.7 (:issue:`8019`)



Expand Down
5 changes: 4 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9610,6 +9610,13 @@ def test_shift_bool(self):
columns=['high', 'low'])
assert_frame_equal(rs, xp)

def test_shift_empty(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put the issue number here in a comment

# Regression test for #8019
df = DataFrame({'foo': []})
rs = df.shift(-1)

assert_frame_equal(df, rs)

def test_tshift(self):
# PeriodIndex
ps = tm.makePeriodFrame()
Expand Down