Skip to content
Closed
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 @@ -224,6 +224,7 @@ Other API changes
- 3rd party ``py.path`` objects are no longer explicitly supported in IO methods. Use :py:class:`pathlib.Path` objects instead (:issue:`57091`)
- :func:`read_table`'s ``parse_dates`` argument defaults to ``None`` to improve consistency with :func:`read_csv` (:issue:`57476`)
- Made ``dtype`` a required argument in :meth:`ExtensionArray._from_sequence_of_strings` (:issue:`56519`)
- Removed ``inplace`` argument in :meth:`Resampler.interpolate`. (:issue:`58690`)
- Updated :meth:`DataFrame.to_excel` so that the output spreadsheet has no styling. Custom styling can still be done using :meth:`Styler.to_excel` (:issue:`54154`)
- pickle and HDF (``.h5``) files created with Python 2 are no longer explicitly supported (:issue:`57387`)
- pickled objects from pandas version less than ``1.0.0`` are no longer supported (:issue:`57155`)
Expand Down
7 changes: 3 additions & 4 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,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,
Expand Down Expand Up @@ -808,8 +807,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 @@ -909,6 +906,8 @@ def interpolate(
``07:00:00`` and ``07:00:02``.
"""
assert downcast is lib.no_default # just checking coverage
if kwargs.get("inplace"):
raise ValueError("The argument 'inplace' is no longer supported.")
result = self._upsample("asfreq")

# If the original data has timestamps which are not aligned with the
Expand Down Expand Up @@ -942,7 +941,7 @@ def interpolate(
method=method,
axis=axis,
limit=limit,
inplace=inplace,
inplace=False,
limit_direction=limit_direction,
limit_area=limit_area,
downcast=downcast,
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/copy_view/test_interp_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_interpolate_downcast_reference_triggers_copy():

msg = "Can not interpolate with method=pad"
with pytest.raises(ValueError, match=msg):
df.interpolate(method="pad", inplace=True, downcast="infer")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that a lot of interpolate usages are still modified in the PR. Only tests that used to call.resample(...).interpolate(interpolate=) should have been changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mroeschke Sorry for the long delay. I was checking this now again and I think we need to clear up the misunderstanding. The wrong behavior is not just related to cases that use .resample(...). See this minimal example (adjusted from the test case I fixed in the other PR):

from pandas import DataFrame, testing as tm, Timestamp
import numpy as np

df = DataFrame(
    {
        "A": [1, 2, np.nan, 4],
        "B": [1, 4, 9, np.nan],
        "C": [Timestamp("2020-08-01 00:00:01"), Timestamp("2020-08-01 00:00:02"), Timestamp("2020-08-01 00:00:03"), Timestamp("2020-08-01 00:00:05")],
        "D": list("abcd"),
    }
)

result = df.set_index("C").interpolate()
expected = df.set_index("C")
expected.loc[Timestamp("2020-08-01 00:00:03"), "A"] = 2.66667
expected.loc[Timestamp("2020-08-01 00:00:05"), "B"] = 9
tm.assert_frame_equal(result, expected)

In pandas 2.* this fails with

---------------------------------------------------------------------------
AssertionError: DataFrame.iloc[:, 0] (column name="A") are different

DataFrame.iloc[:, 0] (column name="A") values are different (25.0 %)
[index]: [2020-08-01T00:00:01.000000000, 2020-08-01T00:00:02.000000000, 2020-08-01T00:00:03.000000000, 2020-08-01T00:00:05.000000000]
[left]:  [1.0, 2.0, 3.0, 4.0]
[right]: [1.0, 2.0, 2.66667, 4.0]
At positional index 2, first diff: 3.0 != 2.66667

This is not using resample. Can you please clarify?

df.interpolate(method="pad", inplace=False, downcast="infer")
assert df._mgr._has_no_reference(0)
assert not np.shares_memory(arr_a, get_array(df, "a"))

Expand Down Expand Up @@ -285,7 +285,7 @@ def test_fillna_chained_assignment():
tm.assert_frame_equal(df, df_orig)


@pytest.mark.parametrize("func", ["interpolate", "ffill", "bfill"])
@pytest.mark.parametrize("func", ["ffill", "bfill"])
def test_interpolate_chained_assignment(func):
df = DataFrame({"a": [1, np.nan, 2], "b": 1})
df_orig = df.copy()
Expand Down
60 changes: 2 additions & 58 deletions pandas/tests/frame/methods/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ def test_interpolate_datetimelike_values(self, frame_or_series):
expected_td = frame_or_series(orig - orig[0])
tm.assert_equal(res_td, expected_td)

def test_interpolate_inplace(self, frame_or_series, request):
# GH#44749
obj = frame_or_series([1, np.nan, 2])
orig = obj.values

obj.interpolate(inplace=True)
expected = frame_or_series([1, 1.5, 2])
tm.assert_equal(obj, expected)

# check we operated *actually* inplace
assert np.shares_memory(orig, obj.values)
assert orig.squeeze()[1] == 1.5

@pytest.mark.xfail(
using_pyarrow_string_dtype(), reason="interpolate doesn't work for string"
)
Expand All @@ -80,15 +67,6 @@ def test_interp_basic(self):
with pytest.raises(TypeError, match=msg):
df.interpolate()

cvalues = df["C"]._values
dvalues = df["D"].values
with pytest.raises(TypeError, match=msg):
df.interpolate(inplace=True)

# check we DID operate inplace
assert np.shares_memory(df["C"]._values, cvalues)
assert np.shares_memory(df["D"]._values, dvalues)

@pytest.mark.xfail(
using_pyarrow_string_dtype(), reason="interpolate doesn't work for string"
)
Expand Down Expand Up @@ -307,26 +285,6 @@ def test_interp_raise_on_all_object_dtype(self):
with pytest.raises(TypeError, match=msg):
df.interpolate()

def test_interp_inplace(self):
df = DataFrame({"a": [1.0, 2.0, np.nan, 4.0]})
expected = df.copy()
result = df.copy()

with tm.raises_chained_assignment_error():
return_value = result["a"].interpolate(inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected)

def test_interp_inplace_row(self):
# GH 10395
result = DataFrame(
{"a": [1.0, 2.0, 3.0, 4.0], "b": [np.nan, 2.0, 3.0, 4.0], "c": [3, 2, 2, 2]}
)
expected = result.interpolate(method="linear", axis=1, inplace=False)
return_value = result.interpolate(method="linear", axis=1, inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected)

def test_interp_ignore_all_good(self):
# GH
df = DataFrame(
Expand All @@ -352,19 +310,6 @@ def test_interp_ignore_all_good(self):
result = df[["B", "D"]].interpolate()
tm.assert_frame_equal(result, df[["B", "D"]])

def test_interp_time_inplace_axis(self):
# GH 9687
periods = 5
idx = date_range(start="2014-01-01", periods=periods)
data = np.random.default_rng(2).random((periods, periods))
data[data < 0.5] = np.nan
expected = DataFrame(index=idx, columns=idx, data=data)

result = expected.interpolate(axis=0, method="time")
return_value = expected.interpolate(axis=0, method="time", inplace=True)
assert return_value is None
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("axis_name, axis_number", [("index", 0), ("columns", 1)])
def test_interp_string_axis(self, axis_name, axis_number):
# https://github.com/pandas-dev/pandas/issues/25190
Expand Down Expand Up @@ -400,9 +345,8 @@ def test_interpolate_empty_df(self):
# GH#53199
df = DataFrame()
expected = df.copy()
result = df.interpolate(inplace=True)
assert result is None
tm.assert_frame_equal(df, expected)
result = df.interpolate()
tm.assert_frame_equal(result, expected)

def test_interpolate_ea(self, any_int_ea_dtype):
# GH#55347
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/generic/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ def test_validate_bool_args(self, value):
with pytest.raises(ValueError, match=msg):
df.copy().replace(to_replace=1, value=7, inplace=value)

with pytest.raises(ValueError, match=msg):
df.copy().interpolate(inplace=value)

with pytest.raises(ValueError, match=msg):
df.copy()._where(cond=df.a > 2, inplace=value)

Expand Down