From 91ec0d61cbbc136e6b3756267df8a73e7ecbbef4 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 16 May 2021 14:49:54 +0100 Subject: [PATCH] deprecate nonkeywordargs in interpolate --- doc/source/whatsnew/v1.3.0.rst | 1 + pandas/core/generic.py | 2 ++ pandas/tests/frame/methods/test_interpolate.py | 10 ++++++++++ pandas/tests/resample/test_datetime_index.py | 8 +++++--- pandas/tests/resample/test_resample_api.py | 11 +++++++++++ pandas/tests/series/methods/test_interpolate.py | 10 ++++++++++ 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 622029adf357fb..f881cf569118aa 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -647,6 +647,7 @@ Deprecations - Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`) - 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`) - Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`) +- Deprecated passing arguments as positional in :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` (:issue:`41485`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a09cc0a6324c00..68112fadcf5148 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -61,6 +61,7 @@ InvalidIndexError, ) from pandas.util._decorators import ( + deprecate_nonkeyword_arguments, doc, rewrite_axis_style_signature, ) @@ -6696,6 +6697,7 @@ def replace( else: return result.__finalize__(self, method="replace") + @deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"]) @final def interpolate( self: FrameOrSeries, diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index 5c6fcec887dfb9..e55a25702319cc 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -342,3 +342,13 @@ def test_interp_fillna_methods(self, axis, method): expected = df.fillna(axis=axis, method=method) result = df.interpolate(method=method, axis=axis) tm.assert_frame_equal(result, expected) + + def test_interpolate_pos_args_deprecation(self): + # https://github.com/pandas-dev/pandas/issues/41485 + df = DataFrame({"a": [1, 2, 3]}) + msg = ( + r"Starting with Pandas version 2\.0 all arguments of interpolate except " + r"for the argument 'self' will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df.interpolate(0) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 1c7aa5c444da95..155c509e44169a 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -1026,12 +1026,14 @@ def test_resample_dtype_coercion(): df = {"a": [1, 3, 1, 4]} df = DataFrame(df, index=date_range("2017-01-01", "2017-01-04")) - expected = df.astype("float64").resample("H").mean()["a"].interpolate("cubic") + expected = ( + df.astype("float64").resample("H").mean()["a"].interpolate(method="cubic") + ) - result = df.resample("H")["a"].mean().interpolate("cubic") + result = df.resample("H")["a"].mean().interpolate(method="cubic") tm.assert_series_equal(result, expected) - result = df.resample("H").mean()["a"].interpolate("cubic") + result = df.resample("H").mean()["a"].interpolate(method="cubic") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 76ac86d7980863..e3171e41dab6d0 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -704,3 +704,14 @@ def test_end_and_end_day_origin( ) tm.assert_series_equal(res, expected) + + +def test_bfill_pos_args_deprecation(self): + # https://github.com/pandas-dev/pandas/issues/41485 + df = DataFrame({"a": [1, 2, 3]}) + msg = ( + r"Starting with Pandas version 2\.0 all arguments of bfill except " + r"for the argument 'self' will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + df.bfill(0) diff --git a/pandas/tests/series/methods/test_interpolate.py b/pandas/tests/series/methods/test_interpolate.py index 5686e6478772df..faaebccd5e8de0 100644 --- a/pandas/tests/series/methods/test_interpolate.py +++ b/pandas/tests/series/methods/test_interpolate.py @@ -811,3 +811,13 @@ def test_interpolate_unsorted_index(self, ascending, expected_values): result = ts.sort_index(ascending=ascending).interpolate(method="index") expected = Series(data=expected_values, index=expected_values, dtype=float) tm.assert_series_equal(result, expected) + + def test_interpolate_pos_args_deprecation(self): + # https://github.com/pandas-dev/pandas/issues/41485 + ser = Series([1, 2, 3]) + msg = ( + r"Starting with Pandas version 2\.0 all arguments of interpolate except " + r"for the argument 'self' will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + ser.interpolate(0)