Skip to content

Commit 9f4c0ba

Browse files
authored
DEPR: inplace keyword in interpolate.resample (#62847)
1 parent c9d96a7 commit 9f4c0ba

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
@@ -738,6 +738,7 @@ Other Deprecations
738738
- Deprecated backward-compatibility behavior for :meth:`DataFrame.select_dtypes` matching "str" dtype when ``np.object_`` is specified (:issue:`61916`)
739739
- Deprecated option "future.no_silent_downcasting", as it is no longer used. In a future version accessing this option will raise (:issue:`59502`)
740740
- 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`)
741+
- Deprecated the 'inplace' keyword from :meth:`Resampler.interpolate`, as passing ``True`` raises ``AttributeError`` (:issue:`58690`)
741742

742743
.. ---------------------------------------------------------------------------
743744
.. _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
**kwargs,
@@ -892,8 +894,6 @@ def interpolate(
892894
limit : int, optional
893895
Maximum number of consecutive NaNs to fill. Must be greater than
894896
0.
895-
inplace : bool, default False
896-
Update the data in place if possible.
897897
limit_direction : {{'forward', 'backward', 'both'}}, Optional
898898
Consecutive NaNs will be filled in this direction.
899899
@@ -987,6 +987,19 @@ def interpolate(
987987
Note that the series correctly decreases between two anchors
988988
``07:00:00`` and ``07:00:02``.
989989
"""
990+
if "inplace" in kwargs:
991+
# GH#58690
992+
warnings.warn(
993+
f"The 'inplace' keyword in {type(self).__name__}.interpolate "
994+
"is deprecated and will be removed in a future version. "
995+
"resample(...).interpolate is never inplace.",
996+
Pandas4Warning,
997+
stacklevel=find_stack_level(),
998+
)
999+
inplace = kwargs.pop("inplace")
1000+
if inplace:
1001+
raise ValueError("Cannot interpolate inplace on a resampled object.")
1002+
9901003
result = self._upsample("asfreq")
9911004

9921005
# If the original data has timestamps which are not aligned with the
@@ -1020,7 +1033,7 @@ def interpolate(
10201033
method=method,
10211034
axis=axis,
10221035
limit=limit,
1023-
inplace=inplace,
1036+
inplace=False,
10241037
limit_direction=limit_direction,
10251038
limit_area=limit_area,
10261039
**kwargs,

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)