Skip to content

Commit 4b5fd9d

Browse files
phoflmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#54927: REGR: interpolate raising if fill_value is given
1 parent 874a329 commit 4b5fd9d

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/whatsnew/v2.1.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Fixed regressions
2121
- Fixed regression in :meth:`DataFrame.to_sql` not roundtripping datetime columns correctly for sqlite (:issue:`54877`)
2222
- Fixed regression in :meth:`MultiIndex.append` raising when appending overlapping :class:`IntervalIndex` levels (:issue:`54934`)
2323
- Fixed regression in :meth:`Series.drop_duplicates` for PyArrow strings (:issue:`54904`)
24+
- Fixed regression in :meth:`Series.interpolate` raising when ``fill_value`` was given (:issue:`54920`)
2425
- Fixed regression in :meth:`Series.value_counts` raising for numeric data if ``bins`` was specified (:issue:`54857`)
2526
- Fixed regression when comparing a :class:`Series` with ``datetime64`` dtype with ``None`` (:issue:`54870`)
2627

pandas/core/generic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8160,10 +8160,11 @@ def interpolate(
81608160
stacklevel=find_stack_level(),
81618161
)
81628162

8163-
if "fill_value" in kwargs:
8163+
if method in fillna_methods and "fill_value" in kwargs:
81648164
raise ValueError(
81658165
"'fill_value' is not a valid keyword for "
8166-
f"{type(self).__name__}.interpolate"
8166+
f"{type(self).__name__}.interpolate with method from "
8167+
f"{fillna_methods}"
81678168
)
81688169

81698170
if isinstance(obj.index, MultiIndex) and method != "linear":

pandas/tests/series/methods/test_interpolate.py

+8
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,11 @@ def test_interpolate_asfreq_raises(self):
858858
with pytest.raises(ValueError, match=msg):
859859
with tm.assert_produces_warning(FutureWarning, match=msg2):
860860
ser.interpolate(method="asfreq")
861+
862+
def test_interpolate_fill_value(self):
863+
# GH#54920
864+
pytest.importorskip("scipy")
865+
ser = Series([np.nan, 0, 1, np.nan, 3, np.nan])
866+
result = ser.interpolate(method="nearest", fill_value=0)
867+
expected = Series([np.nan, 0, 1, 1, 3, 0])
868+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)