Skip to content

Commit 8516c8f

Browse files
authored
DEPR: Deprecate method argument of reindex_like (#58724)
* deprecate 'method' argument in NDFrame.reindex_like * fix whatsnew order * included FutureWarning assertion in test_datetime_index.py * repositioned deprecation in docstring
1 parent 0fc0336 commit 8516c8f

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Other Deprecations
206206
- Deprecated allowing non-keyword arguments in :meth:`Series.to_markdown` except ``buf``. (:issue:`57280`)
207207
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
208208
- 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`)
209+
- Deprecated parameter ``method`` in :meth:`DataFrame.reindex_like` / :meth:`Series.reindex_like` (:issue:`58667`)
209210
- Deprecated using ``epoch`` date format in :meth:`DataFrame.to_json` and :meth:`Series.to_json`, use ``iso`` instead. (:issue:`57063`)
210211
-
211212

pandas/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def pytest_collection_modifyitems(items, config) -> None:
158158
("SeriesGroupBy.idxmin", "The behavior of Series.idxmin"),
159159
("SeriesGroupBy.idxmax", "The behavior of Series.idxmax"),
160160
("to_pytimedelta", "The behavior of TimedeltaProperties.to_pytimedelta"),
161+
("NDFrame.reindex_like", "keyword argument 'method' is deprecated"),
161162
# Docstring divides by zero to show behavior difference
162163
("missing.mask_zero_div_zero", "divide by zero encountered"),
163164
(

pandas/core/generic.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@
9393
InvalidIndexError,
9494
)
9595
from pandas.errors.cow import _chained_assignment_method_msg
96-
from pandas.util._decorators import doc
96+
from pandas.util._decorators import (
97+
deprecate_kwarg,
98+
doc,
99+
)
97100
from pandas.util._exceptions import find_stack_level
98101
from pandas.util._validators import (
99102
check_dtype_backend,
@@ -4301,6 +4304,8 @@ def _check_copy_deprecation(copy):
43014304
stacklevel=find_stack_level(),
43024305
)
43034306

4307+
# issue 58667
4308+
@deprecate_kwarg("method", None)
43044309
@final
43054310
def reindex_like(
43064311
self,
@@ -4328,6 +4333,8 @@ def reindex_like(
43284333
Please note: this is only applicable to DataFrames/Series with a
43294334
monotonically increasing/decreasing index.
43304335
4336+
.. deprecated:: 3.0.0
4337+
43314338
* None (default): don't fill gaps
43324339
* pad / ffill: propagate last valid observation forward to next
43334340
valid

pandas/io/formats/style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3800,7 +3800,7 @@ def _validate_apply_axis_arg(
38003800
f"operations is a Series with 'axis in [0,1]'"
38013801
)
38023802
if isinstance(arg, (Series, DataFrame)): # align indx / cols to data
3803-
arg = arg.reindex_like(data, method=None).to_numpy(**dtype)
3803+
arg = arg.reindex_like(data).to_numpy(**dtype)
38043804
else:
38053805
arg = np.asarray(arg, **dtype)
38063806
assert isinstance(arg, np.ndarray) # mypy requirement

pandas/tests/frame/methods/test_reindex_like.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ def test_reindex_like(self, float_frame):
2222
def test_reindex_like_methods(self, method, expected_values):
2323
df = DataFrame({"x": list(range(5))})
2424

25-
result = df.reindex_like(df, method=method, tolerance=0)
25+
with tm.assert_produces_warning(FutureWarning):
26+
result = df.reindex_like(df, method=method, tolerance=0)
2627
tm.assert_frame_equal(df, result)
27-
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
28+
with tm.assert_produces_warning(FutureWarning):
29+
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
2830
tm.assert_frame_equal(df, result)
2931

3032
def test_reindex_like_subclass(self):

pandas/tests/resample/test_datetime_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,8 @@ def test_resample_consistency(unit):
13001300

13011301
s10 = s.reindex(index=i10, method="bfill")
13021302
s10_2 = s.reindex(index=i10, method="bfill", limit=2)
1303-
rl = s.reindex_like(s10, method="bfill", limit=2)
1303+
with tm.assert_produces_warning(FutureWarning):
1304+
rl = s.reindex_like(s10, method="bfill", limit=2)
13041305
r10_2 = s.resample("10Min").bfill(limit=2)
13051306
r10 = s.resample("10Min").bfill()
13061307

pandas/tests/series/methods/test_reindex_like.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_reindex_like(datetime_series):
2020
series1 = Series([5, None, None], [day1, day2, day3])
2121
series2 = Series([None, None], [day1, day3])
2222

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

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

35-
result = ser.reindex_like(other, method="nearest")
36+
with tm.assert_produces_warning(FutureWarning):
37+
result = ser.reindex_like(other, method="nearest")
3638
tm.assert_series_equal(expected, result)
3739

38-
result = ser.reindex_like(other, method="nearest", tolerance=1)
40+
with tm.assert_produces_warning(FutureWarning):
41+
result = ser.reindex_like(other, method="nearest", tolerance=1)
3942
tm.assert_series_equal(expected, result)
40-
result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4])
43+
with tm.assert_produces_warning(FutureWarning):
44+
result = ser.reindex_like(other, method="nearest", tolerance=[1, 2, 3, 4])
4145
tm.assert_series_equal(expected, result)

0 commit comments

Comments
 (0)