Skip to content

BUG: interpolate with complex dtype #53635

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 2 commits into from
Jun 13, 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 @@ -406,6 +406,7 @@ 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`)
- Bug in :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` with complex dtype incorrectly failing to fill ``NaN`` entries (:issue:`53635`)
-

MultiIndex
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ def interpolate(
if method == "asfreq": # type: ignore[comparison-overlap]
# clean_fill_method used to allow this
raise
if m is None and self.dtype.kind != "f":
if m is None and self.dtype == _dtype_obj:
# only deal with floats
# bc we already checked that can_hold_na, we don't have int dtype here
# test_interp_basic checks that we make a copy here
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/frame/methods/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@


class TestDataFrameInterpolate:
def test_interpolate_complex(self):
# GH#53635
ser = Series([complex("1+1j"), float("nan"), complex("2+2j")])
assert ser.dtype.kind == "c"

res = ser.interpolate()
expected = Series([ser[0], ser[0] * 1.5, ser[2]])
tm.assert_series_equal(res, expected)

df = ser.to_frame()
res = df.interpolate()
expected = expected.to_frame()
tm.assert_frame_equal(res, expected)

def test_interpolate_datetimelike_values(self, frame_or_series):
# GH#11312, GH#51005
orig = Series(date_range("2012-01-01", periods=5))
Expand Down