Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 18 additions & 5 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
**kwargs,
Expand Down Expand Up @@ -892,8 +894,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.

Expand Down Expand Up @@ -987,6 +987,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.")

result = self._upsample("asfreq")

# If the original data has timestamps which are not aligned with the
Expand Down Expand Up @@ -1020,7 +1033,7 @@ def interpolate(
method=method,
axis=axis,
limit=limit,
inplace=inplace,
inplace=False,
limit_direction=limit_direction,
limit_area=limit_area,
**kwargs,
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/resample/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
Expand Down
Loading