Skip to content

Commit 3fe733d

Browse files
committed
deprecate nonkeywordargs in interpolate
1 parent b2a36bd commit 3fe733d

File tree

6 files changed

+39
-3
lines changed

6 files changed

+39
-3
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ Deprecations
647647
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`)
648648
- Deprecated behavior of :meth:`DatetimeIndex.union` with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`)
649649
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
650+
- Deprecated passing arguments as positional in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`)
650651

651652
.. ---------------------------------------------------------------------------
652653

pandas/core/generic.py

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
InvalidIndexError,
6262
)
6363
from pandas.util._decorators import (
64+
deprecate_nonkeyword_arguments,
6465
doc,
6566
rewrite_axis_style_signature,
6667
)
@@ -6696,6 +6697,7 @@ def replace(
66966697
else:
66976698
return result.__finalize__(self, method="replace")
66986699

6700+
@deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"])
66996701
@final
67006702
def interpolate(
67016703
self: FrameOrSeries,

pandas/tests/frame/methods/test_interpolate.py

+10
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,13 @@ def test_interp_fillna_methods(self, axis, method):
342342
expected = df.fillna(axis=axis, method=method)
343343
result = df.interpolate(method=method, axis=axis)
344344
tm.assert_frame_equal(result, expected)
345+
346+
def test_interpolate_pos_args_deprecation(self):
347+
# https://github.com/pandas-dev/pandas/issues/41485
348+
df = DataFrame({"a": [1, 2, 3]})
349+
msg = (
350+
r"Starting with Pandas version 2\.0 all arguments of interpolate except "
351+
r"for the argument 'self' will be keyword-only"
352+
)
353+
with tm.assert_produces_warning(FutureWarning, match=msg):
354+
df.interpolate(0)

pandas/tests/resample/test_datetime_index.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1026,12 +1026,14 @@ def test_resample_dtype_coercion():
10261026
df = {"a": [1, 3, 1, 4]}
10271027
df = DataFrame(df, index=date_range("2017-01-01", "2017-01-04"))
10281028

1029-
expected = df.astype("float64").resample("H").mean()["a"].interpolate("cubic")
1029+
expected = (
1030+
df.astype("float64").resample("H").mean()["a"].interpolate(method="cubic")
1031+
)
10301032

1031-
result = df.resample("H")["a"].mean().interpolate("cubic")
1033+
result = df.resample("H")["a"].mean().interpolate(interpolate="cubic")
10321034
tm.assert_series_equal(result, expected)
10331035

1034-
result = df.resample("H").mean()["a"].interpolate("cubic")
1036+
result = df.resample("H").mean()["a"].interpolate(interpolate="cubic")
10351037
tm.assert_series_equal(result, expected)
10361038

10371039

pandas/tests/resample/test_resample_api.py

+11
Original file line numberDiff line numberDiff line change
@@ -704,3 +704,14 @@ def test_end_and_end_day_origin(
704704
)
705705

706706
tm.assert_series_equal(res, expected)
707+
708+
709+
def test_bfill_pos_args_deprecation(self):
710+
# https://github.com/pandas-dev/pandas/issues/41485
711+
df = DataFrame({"a": [1, 2, 3]})
712+
msg = (
713+
r"Starting with Pandas version 2\.0 all arguments of bfill except "
714+
r"for the argument 'self' will be keyword-only"
715+
)
716+
with tm.assert_produces_warning(FutureWarning, match=msg):
717+
df.bfill(0)

pandas/tests/series/methods/test_interpolate.py

+10
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,13 @@ def test_interpolate_unsorted_index(self, ascending, expected_values):
811811
result = ts.sort_index(ascending=ascending).interpolate(method="index")
812812
expected = Series(data=expected_values, index=expected_values, dtype=float)
813813
tm.assert_series_equal(result, expected)
814+
815+
def test_interpolate_pos_args_deprecation(self):
816+
# https://github.com/pandas-dev/pandas/issues/41485
817+
ser = Series([1, 2, 3])
818+
msg = (
819+
r"Starting with Pandas version 2\.0 all arguments of interpolate except "
820+
r"for the argument 'self' will be keyword-only"
821+
)
822+
with tm.assert_produces_warning(FutureWarning, match=msg):
823+
ser.interpolate(0)

0 commit comments

Comments
 (0)