Skip to content

Commit 882719a

Browse files
authored
BUG: interpolate with complex dtype (#53635)
* BUG: interpolate with complex dtype * GH ref
1 parent 2f19184 commit 882719a

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ Missing
408408
^^^^^^^
409409
- Bug in :meth:`DataFrame.interpolate` ignoring ``inplace`` when :class:`DataFrame` is empty (:issue:`53199`)
410410
- 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`)
411+
- Bug in :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` with complex dtype incorrectly failing to fill ``NaN`` entries (:issue:`53635`)
411412
-
412413

413414
MultiIndex

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ def interpolate(
13751375
if method == "asfreq": # type: ignore[comparison-overlap]
13761376
# clean_fill_method used to allow this
13771377
raise
1378-
if m is None and self.dtype.kind != "f":
1378+
if m is None and self.dtype == _dtype_obj:
13791379
# only deal with floats
13801380
# bc we already checked that can_hold_na, we don't have int dtype here
13811381
# test_interp_basic checks that we make a copy here

pandas/tests/frame/methods/test_interpolate.py

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313

1414

1515
class TestDataFrameInterpolate:
16+
def test_interpolate_complex(self):
17+
# GH#53635
18+
ser = Series([complex("1+1j"), float("nan"), complex("2+2j")])
19+
assert ser.dtype.kind == "c"
20+
21+
res = ser.interpolate()
22+
expected = Series([ser[0], ser[0] * 1.5, ser[2]])
23+
tm.assert_series_equal(res, expected)
24+
25+
df = ser.to_frame()
26+
res = df.interpolate()
27+
expected = expected.to_frame()
28+
tm.assert_frame_equal(res, expected)
29+
1630
def test_interpolate_datetimelike_values(self, frame_or_series):
1731
# GH#11312, GH#51005
1832
orig = Series(date_range("2012-01-01", periods=5))

0 commit comments

Comments
 (0)