From 030e792b27313a16fed13362ab8953980b75fc45 Mon Sep 17 00:00:00 2001 From: Brock Date: Sat, 25 Oct 2025 14:27:38 -0700 Subject: [PATCH] DEPR: inplace keyword in interpolate.resample --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/core/resample.py | 23 ++++++++++++++++++----- pandas/tests/resample/test_base.py | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 75b4c5c0fe14d..82019c4917fac 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -737,6 +737,7 @@ Other Deprecations - Deprecated backward-compatibility behavior for :meth:`DataFrame.select_dtypes` matching "str" dtype when ``np.object_`` is specified (:issue:`61916`) - Deprecated option "future.no_silent_downcasting", as it is no longer used. In a future version accessing this option will raise (:issue:`59502`) - Deprecated slicing on a :class:`Series` or :class:`DataFrame` with a :class:`DatetimeIndex` using a ``datetime.date`` object, explicitly cast to :class:`Timestamp` instead (:issue:`35830`) +- Deprecated the 'inplace' keyword from :meth:`Resampler.interpolate`, as passing ``True`` raises ``AttributeError`` (:issue:`58690`) .. --------------------------------------------------------------------------- .. _whatsnew_300.prior_deprecations: diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 3a4ce952ffdcf..4e638be8e1052 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -26,7 +26,10 @@ to_offset, ) from pandas._typing import NDFrameT -from pandas.errors import AbstractMethodError +from pandas.errors import ( + AbstractMethodError, + Pandas4Warning, +) from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.dtypes import ( @@ -847,7 +850,6 @@ def interpolate( *, axis: Axis = 0, limit: int | None = None, - inplace: bool = False, limit_direction: Literal["forward", "backward", "both"] = "forward", limit_area=None, downcast=lib.no_default, @@ -893,8 +895,6 @@ def interpolate( limit : int, optional Maximum number of consecutive NaNs to fill. Must be greater than 0. - inplace : bool, default False - Update the data in place if possible. limit_direction : {{'forward', 'backward', 'both'}}, Optional Consecutive NaNs will be filled in this direction. @@ -993,6 +993,19 @@ def interpolate( Note that the series correctly decreases between two anchors ``07:00:00`` and ``07:00:02``. """ + if "inplace" in kwargs: + # GH#58690 + warnings.warn( + f"The 'inplace' keyword in {type(self).__name__}.interpolate " + "is deprecated and will be removed in a future version. " + "resample(...).interpolate is never inplace.", + Pandas4Warning, + stacklevel=find_stack_level(), + ) + inplace = kwargs.pop("inplace") + if inplace: + raise ValueError("Cannot interpolate inplace on a resampled object.") + assert downcast is lib.no_default # just checking coverage result = self._upsample("asfreq") @@ -1027,7 +1040,7 @@ def interpolate( method=method, axis=axis, limit=limit, - inplace=inplace, + inplace=False, limit_direction=limit_direction, limit_area=limit_area, downcast=downcast, diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 12128be7c2d30..6bfad10b5c32d 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -3,6 +3,8 @@ import numpy as np import pytest +from pandas.errors import Pandas4Warning + from pandas.core.dtypes.common import is_extension_array_dtype import pandas as pd @@ -109,6 +111,22 @@ def test_resample_interpolate(index): tm.assert_frame_equal(result, expected) +def test_resample_interpolate_inplace_deprecated(): + # GH#58690 + dti = date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="D") + + df = DataFrame(range(len(dti)), index=dti) + rs = df.resample("1min") + msg = "The 'inplace' keyword in DatetimeIndexResampler.interpolate" + with tm.assert_produces_warning(Pandas4Warning, match=msg): + rs.interpolate(inplace=False) + + msg2 = "Cannot interpolate inplace on a resampled object" + with pytest.raises(ValueError, match=msg2): + with tm.assert_produces_warning(Pandas4Warning, match=msg): + rs.interpolate(inplace=True) + + def test_resample_interpolate_regular_sampling_off_grid( all_1d_no_arg_interpolation_methods, ):