Skip to content

CLN GH22985 Fixed interpolation with object error message #23044

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
Oct 10, 2018
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
4 changes: 3 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6387,7 +6387,9 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,

if _maybe_transposed_self._data.get_dtype_counts().get(
'object') == len(_maybe_transposed_self.T):
raise TypeError("Cannot interpolate with all NaNs.")
raise TypeError("Cannot interpolate with all object-dtype columns "
"in the DataFrame. Try setting at least one "
"column to a numeric dtype.")

# create/use the index
if method == 'linear':
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,19 @@ def test_interp_raise_on_only_mixed(self):
with pytest.raises(TypeError):
df.interpolate(axis=1)

def test_interp_raise_on_all_object_dtype(self):
# GH 22985
df = DataFrame({
Copy link
Member

@jschendel jschendel Oct 8, 2018

Choose a reason for hiding this comment

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

Can you add the GitHub issue number as a comment? See two tests below for an example. It's useful if someone makes changes that cause this test to break, as it allows them to quickly find the discussion and context for the test.

'A': [1, 2, 3],
'B': [4, 5, 6]},
dtype='object')
with tm.assert_raises_regex(
TypeError,
"Cannot interpolate with all object-dtype columns "
"in the DataFrame. Try setting at least one "
"column to a numeric dtype."):
df.interpolate()

def test_interp_inplace(self):
df = DataFrame({'a': [1., 2., np.nan, 4.]})
expected = DataFrame({'a': [1., 2., 3., 4.]})
Expand Down