Skip to content

BUG: fix for interp with axis=1 and inplace #9695

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

Closed
Closed
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
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ Performance Improvements

Bug Fixes
~~~~~~~~~


- Fixed bug with inplace interpolace along the "columns" axis (:issue:`9687`)
5 changes: 3 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2736,10 +2736,11 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
if self.ndim > 2:
raise NotImplementedError("Interpolate has not been implemented "
"on Panel and Panel 4D objects.")

axis = self._get_axis_number(axis)
if axis == 0:
ax = self._info_axis_name
elif axis == 1:
orig = self
self = self.T
ax = 1
ax = self._get_axis_number(ax)
Expand Down Expand Up @@ -2777,7 +2778,7 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
if inplace:
if axis == 1:
self._update_inplace(new_data)
self = self.T
orig._data = self.T._data
else:
self._update_inplace(new_data)
else:
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8683,9 +8683,6 @@ def test_replace_simple_nested_dict_with_nonexistent_value(self):
result = df.replace({'col': {-1: '-', 1: 'a', 4: 'b'}})
tm.assert_frame_equal(expected, result)

def test_interpolate(self):
pass

def test_replace_value_is_none(self):
self.assertRaises(TypeError, self.tsframe.replace, nan)
orig_value = self.tsframe.iloc[0, 0]
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,20 @@ def test_interp_ignore_all_good(self):
result = df[['B', 'D']].interpolate(downcast=None)
assert_frame_equal(result, df[['B', 'D']])

def test_interp_inplace_axis1(self):
# GH 9687
df = DataFrame({'A': [1, 2, 3], 'B': [2, np.nan, 6],
'C': [3, 4, 5]})
df.interpolate(axis=1, inplace=True)
# dtypes... a bit strange here.
# df.T w/ [int, float, int] -> [float, float, float] dtypes
# this test may break if we change that in the future.
expected = DataFrame({'A': [1., 2, 3], 'B': [2., 3, 6],
'C': [3., 4, 5]})
assert_frame_equal(df, expected)
self.assertIs(df, df)


def test_describe(self):
desc = tm.makeDataFrame().describe()
desc = tm.makeMixedDataFrame().describe()
Expand Down