From 0efb67a345bebecbe7dc6acb6fd31ac92c79121e Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 12 Jun 2023 18:45:16 -0700 Subject: [PATCH 1/2] BUG: interpolate with complex dtype --- doc/source/whatsnew/v2.1.0.rst | 1 + pandas/core/internals/blocks.py | 2 +- pandas/tests/frame/methods/test_interpolate.py | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index ba5334b2f4fa8..f2d00a56123e8 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -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:`??`) - MultiIndex diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index d0efa402089dc..981e29df2c323 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -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 diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index 5a3d53eb96a52..aa165e9bff055 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -13,6 +13,19 @@ class TestDataFrameInterpolate: + def test_interpolate_complex(self): + 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)) From 2d21e0ff3af25cfcc539652f207204005fea9427 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 12 Jun 2023 18:46:27 -0700 Subject: [PATCH 2/2] GH ref --- doc/source/whatsnew/v2.1.0.rst | 2 +- pandas/tests/frame/methods/test_interpolate.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index f2d00a56123e8..e5dd9e6eb86cc 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -406,7 +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:`??`) +- Bug in :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` with complex dtype incorrectly failing to fill ``NaN`` entries (:issue:`53635`) - MultiIndex diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index aa165e9bff055..151e281b5ded2 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -14,6 +14,7 @@ class TestDataFrameInterpolate: def test_interpolate_complex(self): + # GH#53635 ser = Series([complex("1+1j"), float("nan"), complex("2+2j")]) assert ser.dtype.kind == "c"