Skip to content

Commit 1a4d3ad

Browse files
phoflmroeschke
andcommitted
REGR: interpolate raising if fill_value is given (pandas-dev#54927)
* REGR: interpolate raising if fill_value is given * Update test and message * Update pandas/core/generic.py --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent d0cc133 commit 1a4d3ad

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
@@ -8225,10 +8225,11 @@ def interpolate(
82258225
stacklevel=find_stack_level(),
82268226
)
82278227

8228-
if "fill_value" in kwargs:
8228+
if method in fillna_methods and "fill_value" in kwargs:
82298229
raise ValueError(
82308230
"'fill_value' is not a valid keyword for "
8231-
f"{type(self).__name__}.interpolate"
8231+
f"{type(self).__name__}.interpolate with method from "
8232+
f"{fillna_methods}"
82328233
)
82338234

82348235
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)