Skip to content

Shift named axis #6725

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
Mar 28, 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
1 change: 1 addition & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3232,6 +3232,7 @@ def shift(self, periods=1, freq=None, axis=0, **kwds):
if periods == 0:
return self

axis = self._get_axis_number(axis)
if freq is None and not len(kwds):
new_data = self._data.shift(periods=periods, axis=axis)
else:
Expand Down
14 changes: 10 additions & 4 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5439,13 +5439,13 @@ def test_to_csv_deprecated_options(self):
self.tsframe.to_csv(path, nanRep='foo')
recons = read_csv(path,index_col=0,parse_dates=[0],na_values=['foo'])
assert_frame_equal(self.tsframe, recons)

with tm.assert_produces_warning(FutureWarning):
self.frame.to_csv(path, cols=['A', 'B'])

with tm.assert_produces_warning(False):
self.frame.to_csv(path, columns=['A', 'B'])


def test_to_csv_from_csv(self):

Expand Down Expand Up @@ -9194,6 +9194,12 @@ def test_shift(self):
result = df.shift(1,axis=1)
assert_frame_equal(result,expected)

# shift named axis
df = DataFrame(np.random.rand(10,5))
expected = pd.concat([DataFrame(np.nan,index=df.index,columns=[0]),df.iloc[:,0:-1]],ignore_index=True,axis=1)
result = df.shift(1,axis='columns')
assert_frame_equal(result,expected)

def test_shift_bool(self):
df = DataFrame({'high': [True, False],
'low': [False, False]})
Expand Down Expand Up @@ -9827,7 +9833,7 @@ def test_sort_nan(self):
df = DataFrame({'A': [1, 2, nan, 1, 6, 8, 4],
'B': [9, nan, 5, 2, 5, 4, 5]},
index = [1, 2, 3, 4, 5, 6, nan])

# NaN label, ascending=True, na_position='last'
sorted_df = df.sort(kind='quicksort', ascending=True, na_position='last')
expected = DataFrame({'A': [1, 2, nan, 1, 6, 8, 4],
Expand Down Expand Up @@ -9884,7 +9890,7 @@ def test_stable_descending_multicolumn_sort(self):
sorted_df = df.sort(['A','B'], ascending=[0,0], na_position='first',
kind='mergesort')
assert_frame_equal(sorted_df, expected)

def test_sort_index_multicolumn(self):
import random
A = np.arange(5).repeat(20)
Expand Down