Skip to content

BUG: Interpolate not respecting inplace for empty df #53223

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
May 15, 2023
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 doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ Indexing

Missing
^^^^^^^
- Bug in :meth:`DataFrame.interpolate` ignoring ``inplace`` when :class:`DataFrame` is empty (:issue:`53199`)
- Bug in :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` failing to raise on invalid ``downcast`` keyword, which can be only ``None`` or "infer" (:issue:`53103`)
-

Expand Down
2 changes: 2 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7778,6 +7778,8 @@ def interpolate(
obj = self.T if should_transpose else self

if obj.empty:
if inplace:
return None
return self.copy()

if method not in fillna_methods:
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/methods/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,11 @@ def test_interp_fillna_methods(self, request, axis, method, using_array_manager)
expected = df.fillna(axis=axis, method=method)
result = df.interpolate(method=method, axis=axis)
tm.assert_frame_equal(result, expected)

def test_interpolate_empty_df(self):
# GH#53199
df = DataFrame()
expected = df.copy()
result = df.interpolate(inplace=True)
assert result is None
tm.assert_frame_equal(df, expected)