Skip to content

Commit 030e792

Browse files
committed
DEPR: inplace keyword in interpolate.resample
1 parent ea75dd7 commit 030e792

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ Other Deprecations
737737
- Deprecated backward-compatibility behavior for :meth:`DataFrame.select_dtypes` matching "str" dtype when ``np.object_`` is specified (:issue:`61916`)
738738
- Deprecated option "future.no_silent_downcasting", as it is no longer used. In a future version accessing this option will raise (:issue:`59502`)
739739
- 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`)
740+
- Deprecated the 'inplace' keyword from :meth:`Resampler.interpolate`, as passing ``True`` raises ``AttributeError`` (:issue:`58690`)
740741

741742
.. ---------------------------------------------------------------------------
742743
.. _whatsnew_300.prior_deprecations:

pandas/core/resample.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
to_offset,
2727
)
2828
from pandas._typing import NDFrameT
29-
from pandas.errors import AbstractMethodError
29+
from pandas.errors import (
30+
AbstractMethodError,
31+
Pandas4Warning,
32+
)
3033
from pandas.util._exceptions import find_stack_level
3134

3235
from pandas.core.dtypes.dtypes import (
@@ -847,7 +850,6 @@ def interpolate(
847850
*,
848851
axis: Axis = 0,
849852
limit: int | None = None,
850-
inplace: bool = False,
851853
limit_direction: Literal["forward", "backward", "both"] = "forward",
852854
limit_area=None,
853855
downcast=lib.no_default,
@@ -893,8 +895,6 @@ def interpolate(
893895
limit : int, optional
894896
Maximum number of consecutive NaNs to fill. Must be greater than
895897
0.
896-
inplace : bool, default False
897-
Update the data in place if possible.
898898
limit_direction : {{'forward', 'backward', 'both'}}, Optional
899899
Consecutive NaNs will be filled in this direction.
900900
@@ -993,6 +993,19 @@ def interpolate(
993993
Note that the series correctly decreases between two anchors
994994
``07:00:00`` and ``07:00:02``.
995995
"""
996+
if "inplace" in kwargs:
997+
# GH#58690
998+
warnings.warn(
999+
f"The 'inplace' keyword in {type(self).__name__}.interpolate "
1000+
"is deprecated and will be removed in a future version. "
1001+
"resample(...).interpolate is never inplace.",
1002+
Pandas4Warning,
1003+
stacklevel=find_stack_level(),
1004+
)
1005+
inplace = kwargs.pop("inplace")
1006+
if inplace:
1007+
raise ValueError("Cannot interpolate inplace on a resampled object.")
1008+
9961009
assert downcast is lib.no_default # just checking coverage
9971010
result = self._upsample("asfreq")
9981011

@@ -1027,7 +1040,7 @@ def interpolate(
10271040
method=method,
10281041
axis=axis,
10291042
limit=limit,
1030-
inplace=inplace,
1043+
inplace=False,
10311044
limit_direction=limit_direction,
10321045
limit_area=limit_area,
10331046
downcast=downcast,

pandas/tests/resample/test_base.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55

6+
from pandas.errors import Pandas4Warning
7+
68
from pandas.core.dtypes.common import is_extension_array_dtype
79

810
import pandas as pd
@@ -109,6 +111,22 @@ def test_resample_interpolate(index):
109111
tm.assert_frame_equal(result, expected)
110112

111113

114+
def test_resample_interpolate_inplace_deprecated():
115+
# GH#58690
116+
dti = date_range(datetime(2005, 1, 1), datetime(2005, 1, 10), freq="D")
117+
118+
df = DataFrame(range(len(dti)), index=dti)
119+
rs = df.resample("1min")
120+
msg = "The 'inplace' keyword in DatetimeIndexResampler.interpolate"
121+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
122+
rs.interpolate(inplace=False)
123+
124+
msg2 = "Cannot interpolate inplace on a resampled object"
125+
with pytest.raises(ValueError, match=msg2):
126+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
127+
rs.interpolate(inplace=True)
128+
129+
112130
def test_resample_interpolate_regular_sampling_off_grid(
113131
all_1d_no_arg_interpolation_methods,
114132
):

0 commit comments

Comments
 (0)