From ea5da83a08c9498f5b61aa07d20bc0a57adce2cd Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Sun, 16 May 2021 14:41:07 +0100 Subject: [PATCH] deprecate nonkeyword args for bfill --- doc/source/whatsnew/v1.3.0.rst | 1 + pandas/core/generic.py | 1 + pandas/tests/frame/methods/test_fillna.py | 10 ++++++++++ pandas/tests/series/methods/test_fillna.py | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 622029adf357f..10c3ca0ebe6d9 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.bfill` and :meth:`Series.bfill` (:issue:`41485`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a09cc0a6324c0..07699906b547b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6490,6 +6490,7 @@ def bfill( ) -> FrameOrSeries | None: ... + @deprecate_nonkeyword_arguments(version="2.0", allowed_args=["self"]) @final @doc(klass=_shared_doc_kwargs["klass"]) def bfill( diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index b827547b0753e..d41bfdbac3de7 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -334,6 +334,16 @@ def test_bfill(self, datetime_frame): datetime_frame.bfill(), datetime_frame.fillna(method="bfill") ) + 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) + def test_frame_pad_backfill_limit(self): index = np.arange(10) df = DataFrame(np.random.randn(10, 4), index=index) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 51864df915f8c..a5bd00fab79f4 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -776,6 +776,16 @@ def test_bfill(self): ts[2] = np.NaN tm.assert_series_equal(ts.bfill(), ts.fillna(method="bfill")) + def test_bfill_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 bfill except " + r"for the argument 'self' will be keyword-only" + ) + with tm.assert_produces_warning(FutureWarning, match=msg): + ser.bfill(0) + def test_pad_nan(self): x = Series( [np.nan, 1.0, np.nan, 3.0, np.nan], ["z", "a", "b", "c", "d"], dtype=float