Skip to content

DEPR: Deprecate method argument of reindex_like #58724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2024
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 @@ -206,6 +206,7 @@ Other Deprecations
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
- Deprecated behavior of :meth:`Series.dt.to_pytimedelta`, in a future version this will return a :class:`Series` containing python ``datetime.timedelta`` objects instead of an ``ndarray`` of timedelta; this matches the behavior of other :meth:`Series.dt` properties. (:issue:`57463`)
- Deprecated parameter ``method`` in :meth:`DataFrame.reindex_like` / :meth:`Series.reindex_like` (:issue:`58667`)
- Deprecated using ``epoch`` date format in :meth:`DataFrame.to_json` and :meth:`Series.to_json`, use ``iso`` instead. (:issue:`57063`)
-

Expand Down
1 change: 1 addition & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def pytest_collection_modifyitems(items, config) -> None:
("SeriesGroupBy.idxmin", "The behavior of Series.idxmin"),
("SeriesGroupBy.idxmax", "The behavior of Series.idxmax"),
("to_pytimedelta", "The behavior of TimedeltaProperties.to_pytimedelta"),
("NDFrame.reindex_like", "keyword argument 'method' is deprecated"),
# Docstring divides by zero to show behavior difference
("missing.mask_zero_div_zero", "divide by zero encountered"),
(
Expand Down
9 changes: 8 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@
InvalidIndexError,
)
from pandas.errors.cow import _chained_assignment_method_msg
from pandas.util._decorators import doc
from pandas.util._decorators import (
deprecate_kwarg,
doc,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import (
check_dtype_backend,
Expand Down Expand Up @@ -4301,6 +4304,8 @@ def _check_copy_deprecation(copy):
stacklevel=find_stack_level(),
)

# issue 58667
@deprecate_kwarg("method", None)
@final
def reindex_like(
self,
Expand Down Expand Up @@ -4328,6 +4333,8 @@ def reindex_like(
Please note: this is only applicable to DataFrames/Series with a
monotonically increasing/decreasing index.

.. deprecated:: 3.0.0

* None (default): don't fill gaps
* pad / ffill: propagate last valid observation forward to next
valid
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -3800,7 +3800,7 @@ def _validate_apply_axis_arg(
f"operations is a Series with 'axis in [0,1]'"
)
if isinstance(arg, (Series, DataFrame)): # align indx / cols to data
arg = arg.reindex_like(data, method=None).to_numpy(**dtype)
arg = arg.reindex_like(data).to_numpy(**dtype)
else:
arg = np.asarray(arg, **dtype)
assert isinstance(arg, np.ndarray) # mypy requirement
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/frame/methods/test_reindex_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def test_reindex_like(self, float_frame):
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})

result = df.reindex_like(df, method=method, tolerance=0)
with tm.assert_produces_warning(FutureWarning):
result = df.reindex_like(df, method=method, tolerance=0)
tm.assert_frame_equal(df, result)
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
with tm.assert_produces_warning(FutureWarning):
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
tm.assert_frame_equal(df, result)

def test_reindex_like_subclass(self):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,8 @@ def test_resample_consistency(unit):

s10 = s.reindex(index=i10, method="bfill")
s10_2 = s.reindex(index=i10, method="bfill", limit=2)
rl = s.reindex_like(s10, method="bfill", limit=2)
with tm.assert_produces_warning(FutureWarning):
rl = s.reindex_like(s10, method="bfill", limit=2)
r10_2 = s.resample("10Min").bfill(limit=2)
r10 = s.resample("10Min").bfill()

Expand Down
12 changes: 8 additions & 4 deletions pandas/tests/series/methods/test_reindex_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def test_reindex_like(datetime_series):
series1 = Series([5, None, None], [day1, day2, day3])
series2 = Series([None, None], [day1, day3])

result = series1.reindex_like(series2, method="pad")
with tm.assert_produces_warning(FutureWarning):
result = series1.reindex_like(series2, method="pad")
expected = Series([5, np.nan], index=[day1, day3])
tm.assert_series_equal(result, expected)

Expand All @@ -32,10 +33,13 @@ def test_reindex_like_nearest():
other = ser.reindex(target, method="nearest")
expected = Series(np.around(target).astype("int64"), target)

result = ser.reindex_like(other, method="nearest")
with tm.assert_produces_warning(FutureWarning):
result = ser.reindex_like(other, method="nearest")
tm.assert_series_equal(expected, result)

result = ser.reindex_like(other, method="nearest", tolerance=1)
with tm.assert_produces_warning(FutureWarning):
result = ser.reindex_like(other, method="nearest", tolerance=1)
tm.assert_series_equal(expected, result)
result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4])
with tm.assert_produces_warning(FutureWarning):
result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4])
tm.assert_series_equal(expected, result)
Loading