diff --git a/doc/source/whatsnew/v0.10.0.rst b/doc/source/whatsnew/v0.10.0.rst index be50c34d7d14c..905583c708905 100644 --- a/doc/source/whatsnew/v0.10.0.rst +++ b/doc/source/whatsnew/v0.10.0.rst @@ -242,18 +242,42 @@ labeled the aggregated group with the end of the interval: the next day). - Calling ``fillna`` on Series or DataFrame with no arguments is no longer valid code. You must either specify a fill value or an interpolation method: -.. ipython:: python - :okwarning: +.. code-block:: ipython - s = pd.Series([np.nan, 1.0, 2.0, np.nan, 4]) - s - s.fillna(0) - s.fillna(method="pad") + In [6]: s = pd.Series([np.nan, 1.0, 2.0, np.nan, 4]) + + In [7]: s + Out[7]: + 0 NaN + 1 1.0 + 2 2.0 + 3 NaN + 4 4.0 + dtype: float64 + + In [8]: s.fillna(0) + Out[8]: + 0 0.0 + 1 1.0 + 2 2.0 + 3 0.0 + 4 4.0 + dtype: float64 + + In [9]: s.fillna(method="pad") + Out[9]: + 0 NaN + 1 1.0 + 2 2.0 + 3 2.0 + 4 4.0 + dtype: float64 Convenience methods ``ffill`` and ``bfill`` have been added: .. ipython:: python + s = pd.Series([np.nan, 1.0, 2.0, np.nan, 4]) s.ffill() diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 7802ef4798659..1aee3862b6f00 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -229,6 +229,7 @@ Removal of prior version deprecations/changes - Removed ``year``, ``month``, ``quarter``, ``day``, ``hour``, ``minute``, and ``second`` keywords in the :class:`PeriodIndex` constructor, use :meth:`PeriodIndex.from_fields` instead (:issue:`55960`) - Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`) - Removed deprecated behavior of :meth:`Series.agg` using :meth:`Series.apply` (:issue:`53325`) +- Removed deprecated keyword ``method`` on :meth:`Series.fillna`, :meth:`DataFrame.fillna` (:issue:`57760`) - Removed option ``mode.use_inf_as_na``, convert inf entries to ``NaN`` before instead (:issue:`51684`) - Removed support for :class:`DataFrame` in :meth:`DataFrame.from_records`(:issue:`51697`) - Removed support for ``errors="ignore"`` in :func:`to_datetime`, :func:`to_timedelta` and :func:`to_numeric` (:issue:`55734`) diff --git a/pandas/conftest.py b/pandas/conftest.py index 5cdb3b59698f5..1d8411c706f90 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -172,10 +172,6 @@ def pytest_collection_modifyitems(items, config) -> None: "DataFrameGroupBy.fillna", "DataFrameGroupBy.fillna with 'method' is deprecated", ), - ( - "DataFrameGroupBy.fillna", - "DataFrame.fillna with 'method' is deprecated", - ), ("read_parquet", "Passing a BlockManager to DataFrame is deprecated"), ] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e501858e73872..8f73003216a41 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6769,7 +6769,6 @@ def fillna( self, value: Hashable | Mapping | Series | DataFrame = ..., *, - method: FillnaOptions | None = ..., axis: Axis | None = ..., inplace: Literal[False] = ..., limit: int | None = ..., @@ -6781,7 +6780,6 @@ def fillna( self, value: Hashable | Mapping | Series | DataFrame = ..., *, - method: FillnaOptions | None = ..., axis: Axis | None = ..., inplace: Literal[True], limit: int | None = ..., @@ -6793,7 +6791,6 @@ def fillna( self, value: Hashable | Mapping | Series | DataFrame = ..., *, - method: FillnaOptions | None = ..., axis: Axis | None = ..., inplace: bool = ..., limit: int | None = ..., @@ -6809,13 +6806,12 @@ def fillna( self, value: Hashable | Mapping | Series | DataFrame | None = None, *, - method: FillnaOptions | None = None, axis: Axis | None = None, inplace: bool = False, limit: int | None = None, ) -> Self | None: """ - Fill NA/NaN values using the specified method. + Fill NA/NaN values with `value`. Parameters ---------- @@ -6825,15 +6821,6 @@ def fillna( each index (for a Series) or column (for a DataFrame). Values not in the dict/Series/DataFrame will not be filled. This value cannot be a list. - method : {{'backfill', 'bfill', 'ffill', None}}, default None - Method to use for filling holes in reindexed Series: - - * ffill: propagate last valid observation forward to next valid. - * backfill / bfill: use next valid observation to fill gap. - - .. deprecated:: 2.1.0 - Use ffill or bfill instead. - axis : {axes_single_arg} Axis along which to fill missing values. For `Series` this parameter is unused and defaults to 0. @@ -6842,12 +6829,8 @@ def fillna( other views on this object (e.g., a no-copy slice for a column in a DataFrame). limit : int, default None - If method is specified, this is the maximum number of consecutive - NaN values to forward/backward fill. In other words, if there is - a gap with more than this number of consecutive NaNs, it will only - be partially filled. If method is not specified, this is the - maximum number of entries along the entire axis where NaNs will be - filled. Must be greater than 0 if not None. + This is the maximum number of entries along the entire axis + where NaNs will be filled. Must be greater than 0 if not None. Returns ------- @@ -6932,14 +6915,10 @@ def fillna( stacklevel=2, ) - value, method = validate_fillna_kwargs(value, method) - if method is not None: - warnings.warn( - f"{type(self).__name__}.fillna with 'method' is deprecated and " - "will raise in a future version. Use obj.ffill() or obj.bfill() " - "instead.", - FutureWarning, - stacklevel=find_stack_level(), + if isinstance(value, (list, tuple)): + raise TypeError( + '"value" parameter must be a scalar or dict, but ' + f'you passed a "{type(value).__name__}"' ) # set the default here, so functions examining the signaure @@ -6949,15 +6928,7 @@ def fillna( axis = self._get_axis_number(axis) if value is None: - return self._pad_or_backfill( - # error: Argument 1 to "_pad_or_backfill" of "NDFrame" has - # incompatible type "Optional[Literal['backfill', 'bfill', 'ffill', - # 'pad']]"; expected "Literal['ffill', 'bfill', 'pad', 'backfill']" - method, # type: ignore[arg-type] - axis=axis, - limit=limit, - inplace=inplace, - ) + raise ValueError("Must specify a fill 'value'.") else: if self.ndim == 1: if isinstance(value, (dict, ABCSeries)): diff --git a/pandas/tests/extension/base/missing.py b/pandas/tests/extension/base/missing.py index b9cba2fc52728..328c6cd6164fb 100644 --- a/pandas/tests/extension/base/missing.py +++ b/pandas/tests/extension/base/missing.py @@ -68,9 +68,6 @@ def test_fillna_scalar(self, data_missing): expected = data_missing.fillna(valid) tm.assert_extension_array_equal(result, expected) - @pytest.mark.filterwarnings( - "ignore:Series.fillna with 'method' is deprecated:FutureWarning" - ) def test_fillna_limit_pad(self, data_missing): arr = data_missing.take([1, 0, 0, 0, 1]) result = pd.Series(arr).ffill(limit=2) @@ -99,12 +96,9 @@ def test_ffill_limit_area( expected = pd.Series(data_missing.take(expected_ilocs)) tm.assert_series_equal(result, expected) - @pytest.mark.filterwarnings( - "ignore:Series.fillna with 'method' is deprecated:FutureWarning" - ) def test_fillna_limit_backfill(self, data_missing): arr = data_missing.take([1, 0, 0, 0, 1]) - result = pd.Series(arr).fillna(method="backfill", limit=2) + result = pd.Series(arr).bfill(limit=2) expected = pd.Series(data_missing.take([1, 0, 1, 1, 1])) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 816b7ace69300..bed3ec62f43da 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -187,15 +187,6 @@ def test_ffill_limit_area( ) def test_fillna_limit_backfill(self, data_missing): - msg = "Series.fillna with 'method' is deprecated" - with tm.assert_produces_warning( - FutureWarning, - match=msg, - check_stacklevel=False, - raise_on_extra_warnings=False, - ): - super().test_fillna_limit_backfill(data_missing) - msg = "ExtensionArray.fillna 'method' keyword is deprecated" with tm.assert_produces_warning( DeprecationWarning, diff --git a/pandas/tests/extension/test_sparse.py b/pandas/tests/extension/test_sparse.py index c3a1d584170fb..d8fa1fa0ed5cf 100644 --- a/pandas/tests/extension/test_sparse.py +++ b/pandas/tests/extension/test_sparse.py @@ -234,11 +234,6 @@ def test_isna(self, data_missing): expected = SparseArray([False, False], fill_value=False, dtype=expected_dtype) tm.assert_equal(sarr.isna(), expected) - def test_fillna_limit_backfill(self, data_missing): - warns = FutureWarning - with tm.assert_produces_warning(warns, check_stacklevel=False): - super().test_fillna_limit_backfill(data_missing) - def test_fillna_no_op_returns_copy(self, data, request): if np.isnan(data.fill_value): request.applymarker( diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index ee660d8b03b40..81f66cfd48b0a 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -58,20 +58,15 @@ def test_fillna_datetime(self, datetime_frame): zero_filled = datetime_frame.fillna(0) assert (zero_filled.loc[zero_filled.index[:5], "A"] == 0).all() - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - padded = datetime_frame.fillna(method="pad") + padded = datetime_frame.ffill() assert np.isnan(padded.loc[padded.index[:5], "A"]).all() assert ( padded.loc[padded.index[-5:], "A"] == padded.loc[padded.index[-5], "A"] ).all() - msg = "Must specify a fill 'value' or 'method'" + msg = "Must specify a fill 'value'" with pytest.raises(ValueError, match=msg): datetime_frame.fillna() - msg = "Cannot specify both 'value' and 'method'" - with pytest.raises(ValueError, match=msg): - datetime_frame.fillna(5, method="ffill") @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="can't fill 0 in string") def test_fillna_mixed_type(self, float_string_frame): @@ -80,9 +75,7 @@ def test_fillna_mixed_type(self, float_string_frame): mf.loc[mf.index[-10:], "A"] = np.nan # TODO: make stronger assertion here, GH 25640 mf.fillna(value=0) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - mf.fillna(method="pad") + mf.ffill() def test_fillna_mixed_float(self, mixed_float_frame): # mixed numeric (but no float16) @@ -90,10 +83,7 @@ def test_fillna_mixed_float(self, mixed_float_frame): mf.loc[mf.index[-10:], "A"] = np.nan result = mf.fillna(value=0) _check_mixed_float(result, dtype={"C": None}) - - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - result = mf.fillna(method="pad") + result = mf.ffill() _check_mixed_float(result, dtype={"C": None}) def test_fillna_different_dtype(self, using_infer_string): @@ -159,9 +149,7 @@ def test_fillna_tzaware(self): ] } ) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - res = df.fillna(method="pad") + res = df.ffill() tm.assert_frame_equal(res, exp) df = DataFrame({"A": [NaT, Timestamp("2012-11-11 00:00:00+01:00")]}) @@ -173,9 +161,7 @@ def test_fillna_tzaware(self): ] } ) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - res = df.fillna(method="bfill") + res = df.bfill() tm.assert_frame_equal(res, exp) def test_fillna_tzaware_different_column(self): @@ -187,9 +173,7 @@ def test_fillna_tzaware_different_column(self): "B": [1, 2, np.nan, np.nan], } ) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.fillna(method="pad") + result = df.ffill() expected = DataFrame( { "A": date_range("20130101", periods=4, tz="US/Eastern"), @@ -220,9 +204,7 @@ def test_na_actions_categorical(self): with pytest.raises(TypeError, match=msg): df.fillna(value={"cats": 4, "vals": "c"}) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - res = df.fillna(method="pad") + res = df.ffill() tm.assert_frame_equal(res, df_exp_fill) # dropna @@ -368,19 +350,14 @@ def test_ffill(self, datetime_frame): datetime_frame.loc[datetime_frame.index[:5], "A"] = np.nan datetime_frame.loc[datetime_frame.index[-5:], "A"] = np.nan - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - alt = datetime_frame.fillna(method="ffill") + alt = datetime_frame.ffill() tm.assert_frame_equal(datetime_frame.ffill(), alt) def test_bfill(self, datetime_frame): datetime_frame.loc[datetime_frame.index[:5], "A"] = np.nan datetime_frame.loc[datetime_frame.index[-5:], "A"] = np.nan - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - alt = datetime_frame.fillna(method="bfill") - + alt = datetime_frame.bfill() tm.assert_frame_equal(datetime_frame.bfill(), alt) def test_frame_pad_backfill_limit(self): @@ -389,16 +366,13 @@ def test_frame_pad_backfill_limit(self): result = df[:2].reindex(index, method="pad", limit=5) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = df[:2].reindex(index).fillna(method="pad") + expected = df[:2].reindex(index).ffill() expected.iloc[-3:] = np.nan tm.assert_frame_equal(result, expected) result = df[-2:].reindex(index, method="backfill", limit=5) - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = df[-2:].reindex(index).fillna(method="backfill") + expected = df[-2:].reindex(index).bfill() expected.iloc[:3] = np.nan tm.assert_frame_equal(result, expected) @@ -407,21 +381,16 @@ def test_frame_fillna_limit(self): df = DataFrame(np.random.default_rng(2).standard_normal((10, 4)), index=index) result = df[:2].reindex(index) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - result = result.fillna(method="pad", limit=5) + result = result.ffill(limit=5) - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = df[:2].reindex(index).fillna(method="pad") + expected = df[:2].reindex(index).ffill() expected.iloc[-3:] = np.nan tm.assert_frame_equal(result, expected) result = df[-2:].reindex(index) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = result.fillna(method="backfill", limit=5) + result = result.bfill(limit=5) - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = df[-2:].reindex(index).fillna(method="backfill") + expected = df[-2:].reindex(index).bfill() expected.iloc[:3] = np.nan tm.assert_frame_equal(result, expected) @@ -465,13 +434,10 @@ def test_fillna_inplace(self): df.loc[:4, 1] = np.nan df.loc[-4:, 3] = np.nan - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = df.fillna(method="ffill") + expected = df.ffill() assert expected is not df - with tm.assert_produces_warning(FutureWarning, match=msg): - df.fillna(method="ffill", inplace=True) + df.ffill(inplace=True) tm.assert_frame_equal(df, expected) def test_fillna_dict_series(self): @@ -542,24 +508,15 @@ def test_fillna_columns(self): arr[:, ::2] = np.nan df = DataFrame(arr) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.fillna(method="ffill", axis=1) - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = df.T.fillna(method="pad").T + result = df.ffill(axis=1) + expected = df.T.ffill().T tm.assert_frame_equal(result, expected) df.insert(6, "foo", 5) - with tm.assert_produces_warning(FutureWarning, match=msg): - result = df.fillna(method="ffill", axis=1) - with tm.assert_produces_warning(FutureWarning, match=msg): - expected = df.astype(float).fillna(method="ffill", axis=1) + result = df.ffill(axis=1) + expected = df.astype(float).ffill(axis=1) tm.assert_frame_equal(result, expected) - def test_fillna_invalid_method(self, float_frame): - with pytest.raises(ValueError, match="ffil"): - float_frame.fillna(method="ffil") - def test_fillna_invalid_value(self, float_frame): # list msg = '"value" parameter must be a scalar or dict, but you passed a "{}"' @@ -580,9 +537,7 @@ def test_fillna_col_reordering(self): cols = ["COL." + str(i) for i in range(5, 0, -1)] data = np.random.default_rng(2).random((20, 5)) df = DataFrame(index=range(20), columns=cols, data=data) - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - filled = df.fillna(method="ffill") + filled = df.ffill() assert df.columns.tolist() == filled.columns.tolist() @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="can't fill 0 in string") diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index 6ca6cbad02d51..eb6d649c296fc 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -757,11 +757,6 @@ def test_replace_for_new_dtypes(self, datetime_frame): tsframe.loc[tsframe.index[:5], "A"] = np.nan tsframe.loc[tsframe.index[-5:], "A"] = np.nan tsframe.loc[tsframe.index[:5], "B"] = np.nan - msg = "DataFrame.fillna with 'method' is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - # TODO: what is this even testing? - result = tsframe.fillna(method="bfill") - tm.assert_frame_equal(result, tsframe.fillna(method="bfill")) @pytest.mark.parametrize( "frame, to_replace, value, expected", diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index fd815c85a89b3..d25d909adea8e 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -89,7 +89,6 @@ (pd.DataFrame, frame_data, operator.methodcaller("rename", columns={"A": "a"})), (pd.DataFrame, frame_data, operator.methodcaller("rename", index=lambda x: x)), (pd.DataFrame, frame_data, operator.methodcaller("fillna", "A")), - (pd.DataFrame, frame_data, operator.methodcaller("fillna", method="ffill")), (pd.DataFrame, frame_data, operator.methodcaller("set_index", "A")), (pd.DataFrame, frame_data, operator.methodcaller("reset_index")), (pd.DataFrame, frame_data, operator.methodcaller("isna")), @@ -375,9 +374,6 @@ def idfn(x): return str(x) -@pytest.mark.filterwarnings( - "ignore:DataFrame.fillna with 'method' is deprecated:FutureWarning", -) @pytest.mark.parametrize("ndframe_method", _all_methods, ids=lambda x: idfn(x[-1])) def test_finalize_called(ndframe_method): cls, init_args, method = ndframe_method diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index a458b31480375..0965d36e4827d 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -25,14 +25,11 @@ from pandas.core.arrays import period_array -@pytest.mark.filterwarnings( - "ignore:(Series|DataFrame).fillna with 'method' is deprecated:FutureWarning" -) class TestSeriesFillNA: def test_fillna_nat(self): series = Series([0, 1, 2, NaT._value], dtype="M8[ns]") - filled = series.fillna(method="pad") + filled = series.ffill() filled2 = series.fillna(value=series.values[2]) expected = series.copy() @@ -42,7 +39,7 @@ def test_fillna_nat(self): tm.assert_series_equal(filled2, expected) df = DataFrame({"A": series}) - filled = df.fillna(method="pad") + filled = df.ffill() filled2 = df.fillna(value=series.values[2]) expected = DataFrame({"A": expected}) tm.assert_frame_equal(filled, expected) @@ -50,7 +47,7 @@ def test_fillna_nat(self): series = Series([NaT._value, 0, 1, 2], dtype="M8[ns]") - filled = series.fillna(method="bfill") + filled = series.bfill() filled2 = series.fillna(value=series[1]) expected = series.copy() @@ -60,39 +57,30 @@ def test_fillna_nat(self): tm.assert_series_equal(filled2, expected) df = DataFrame({"A": series}) - filled = df.fillna(method="bfill") + filled = df.bfill() filled2 = df.fillna(value=series[1]) expected = DataFrame({"A": expected}) tm.assert_frame_equal(filled, expected) tm.assert_frame_equal(filled2, expected) - def test_fillna_value_or_method(self, datetime_series): - msg = "Cannot specify both 'value' and 'method'" - with pytest.raises(ValueError, match=msg): - datetime_series.fillna(value=0, method="ffill") - def test_fillna(self): ts = Series( [0.0, 1.0, 2.0, 3.0, 4.0], index=date_range("2020-01-01", periods=5) ) - tm.assert_series_equal(ts, ts.fillna(method="ffill")) + tm.assert_series_equal(ts, ts.ffill()) ts.iloc[2] = np.nan exp = Series([0.0, 1.0, 1.0, 3.0, 4.0], index=ts.index) - tm.assert_series_equal(ts.fillna(method="ffill"), exp) + tm.assert_series_equal(ts.ffill(), exp) exp = Series([0.0, 1.0, 3.0, 3.0, 4.0], index=ts.index) - tm.assert_series_equal(ts.fillna(method="backfill"), exp) + tm.assert_series_equal(ts.bfill(), exp) exp = Series([0.0, 1.0, 5.0, 3.0, 4.0], index=ts.index) tm.assert_series_equal(ts.fillna(value=5), exp) - msg = "Must specify a fill 'value' or 'method'" - with pytest.raises(ValueError, match=msg): - ts.fillna() - def test_fillna_nonscalar(self): # GH#5703 s1 = Series([np.nan]) @@ -395,7 +383,7 @@ def test_datetime64_fillna_backfill(self): ], dtype="M8[ns]", ) - result = ser.fillna(method="backfill") + result = ser.bfill() tm.assert_series_equal(result, expected) @pytest.mark.parametrize("tz", ["US/Eastern", "Asia/Tokyo"]) @@ -615,7 +603,7 @@ def test_fillna_dt64tz_with_method(self): Timestamp("2012-11-11 00:00:00+01:00"), ] ) - tm.assert_series_equal(ser.fillna(method="pad"), exp) + tm.assert_series_equal(ser.ffill(), exp) ser = Series([NaT, Timestamp("2012-11-11 00:00:00+01:00")]) exp = Series( @@ -624,7 +612,7 @@ def test_fillna_dt64tz_with_method(self): Timestamp("2012-11-11 00:00:00+01:00"), ] ) - tm.assert_series_equal(ser.fillna(method="bfill"), exp) + tm.assert_series_equal(ser.bfill(), exp) def test_fillna_pytimedelta(self): # GH#8209 @@ -807,12 +795,6 @@ def test_fillna_f32_upcast_with_dict(self): # --------------------------------------------------------------- # Invalid Usages - def test_fillna_invalid_method(self, datetime_series): - try: - datetime_series.fillna(method="ffil") - except ValueError as inst: - assert "ffil" in str(inst) - def test_fillna_listlike_invalid(self): ser = Series(np.random.default_rng(2).integers(-100, 100, 50)) msg = '"value" parameter must be a scalar or dict, but you passed a "list"' @@ -834,9 +816,8 @@ def test_fillna_method_and_limit_invalid(self): ] ) for limit in [-1, 0, 1.0, 2.0]: - for method in ["backfill", "bfill", "pad", "ffill", None]: - with pytest.raises(ValueError, match=msg): - ser.fillna(1, limit=limit, method=method) + with pytest.raises(ValueError, match=msg): + ser.fillna(1, limit=limit) def test_fillna_datetime64_with_timezone_tzinfo(self): # https://github.com/pandas-dev/pandas/issues/38851 @@ -877,46 +858,29 @@ def test_fillna_categorical_accept_same_type( tm.assert_categorical_equal(result, expected) -@pytest.mark.filterwarnings( - "ignore:Series.fillna with 'method' is deprecated:FutureWarning" -) class TestFillnaPad: def test_fillna_bug(self): ser = Series([np.nan, 1.0, np.nan, 3.0, np.nan], ["z", "a", "b", "c", "d"]) - filled = ser.fillna(method="ffill") + filled = ser.ffill() expected = Series([np.nan, 1.0, 1.0, 3.0, 3.0], ser.index) tm.assert_series_equal(filled, expected) - filled = ser.fillna(method="bfill") + filled = ser.bfill() expected = Series([1.0, 1.0, 3.0, 3.0, np.nan], ser.index) tm.assert_series_equal(filled, expected) - def test_ffill(self): - ts = Series( - [0.0, 1.0, 2.0, 3.0, 4.0], index=date_range("2020-01-01", periods=5) - ) - ts.iloc[2] = np.nan - tm.assert_series_equal(ts.ffill(), ts.fillna(method="ffill")) - def test_ffill_mixed_dtypes_without_missing_data(self): # GH#14956 series = Series([datetime(2015, 1, 1, tzinfo=pytz.utc), 1]) result = series.ffill() tm.assert_series_equal(series, result) - def test_bfill(self): - ts = Series( - [0.0, 1.0, 2.0, 3.0, 4.0], index=date_range("2020-01-01", periods=5) - ) - ts.iloc[2] = np.nan - tm.assert_series_equal(ts.bfill(), ts.fillna(method="bfill")) - def test_pad_nan(self): x = Series( [np.nan, 1.0, np.nan, 3.0, np.nan], ["z", "a", "b", "c", "d"], dtype=float ) - return_value = x.fillna(method="pad", inplace=True) + return_value = x.ffill(inplace=True) assert return_value is None expected = Series( @@ -930,16 +894,16 @@ def test_series_fillna_limit(self): s = Series(np.random.default_rng(2).standard_normal(10), index=index) result = s[:2].reindex(index) - result = result.fillna(method="pad", limit=5) + result = result.ffill(limit=5) - expected = s[:2].reindex(index).fillna(method="pad") + expected = s[:2].reindex(index).ffill() expected[-3:] = np.nan tm.assert_series_equal(result, expected) result = s[-2:].reindex(index) - result = result.fillna(method="bfill", limit=5) + result = result.bfill(limit=5) - expected = s[-2:].reindex(index).fillna(method="backfill") + expected = s[-2:].reindex(index).bfill() expected[:3] = np.nan tm.assert_series_equal(result, expected) @@ -949,21 +913,21 @@ def test_series_pad_backfill_limit(self): result = s[:2].reindex(index, method="pad", limit=5) - expected = s[:2].reindex(index).fillna(method="pad") + expected = s[:2].reindex(index).ffill() expected[-3:] = np.nan tm.assert_series_equal(result, expected) result = s[-2:].reindex(index, method="backfill", limit=5) - expected = s[-2:].reindex(index).fillna(method="backfill") + expected = s[-2:].reindex(index).bfill() expected[:3] = np.nan tm.assert_series_equal(result, expected) def test_fillna_int(self): ser = Series(np.random.default_rng(2).integers(-100, 100, 50)) - return_value = ser.fillna(method="ffill", inplace=True) + return_value = ser.ffill(inplace=True) assert return_value is None - tm.assert_series_equal(ser.fillna(method="ffill", inplace=False), ser) + tm.assert_series_equal(ser.ffill(inplace=False), ser) def test_datetime64tz_fillna_round_issue(self): # GH#14872