Skip to content

Commit 12cb26a

Browse files
authored
CLN: unused args in pad_or_backfill (#53872)
* CLN: unused args in pad_or_backfill * restore limit_direction validation
1 parent 365e6c9 commit 12cb26a

File tree

5 files changed

+21
-33
lines changed

5 files changed

+21
-33
lines changed

pandas/core/arrays/datetimelike.py

-2
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,6 @@ def interpolate(
22392239
limit,
22402240
limit_direction,
22412241
limit_area,
2242-
fill_value,
22432242
inplace: bool,
22442243
**kwargs,
22452244
) -> Self:
@@ -2263,7 +2262,6 @@ def interpolate(
22632262
limit=limit,
22642263
limit_direction=limit_direction,
22652264
limit_area=limit_area,
2266-
fill_value=fill_value,
22672265
**kwargs,
22682266
)
22692267
if inplace:

pandas/core/arrays/numpy_.py

-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ def interpolate(
267267
limit,
268268
limit_direction,
269269
limit_area,
270-
fill_value,
271270
inplace: bool,
272271
**kwargs,
273272
) -> Self:
@@ -289,7 +288,6 @@ def interpolate(
289288
limit=limit,
290289
limit_direction=limit_direction,
291290
limit_area=limit_area,
292-
fill_value=fill_value,
293291
**kwargs,
294292
)
295293
if inplace:

pandas/core/generic.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -6891,7 +6891,7 @@ def _deprecate_downcast(self, downcast) -> None:
68916891
)
68926892

68936893
@final
6894-
def _fillna_with_method(
6894+
def _pad_or_backfill(
68956895
self,
68966896
method: Literal["ffill", "bfill", "pad", "backfill"],
68976897
*,
@@ -6908,7 +6908,7 @@ def _fillna_with_method(
69086908
if not self._mgr.is_single_block and axis == 1:
69096909
if inplace:
69106910
raise NotImplementedError()
6911-
result = self.T._fillna_with_method(method=method, limit=limit).T
6911+
result = self.T._pad_or_backfill(method=method, limit=limit).T
69126912

69136913
return result
69146914

@@ -7105,8 +7105,8 @@ def fillna(
71057105
axis = self._get_axis_number(axis)
71067106

71077107
if value is None:
7108-
return self._fillna_with_method(
7109-
# error: Argument 1 to "_fillna_with_method" of "NDFrame" has
7108+
return self._pad_or_backfill(
7109+
# error: Argument 1 to "_pad_or_backfill" of "NDFrame" has
71107110
# incompatible type "Optional[Literal['backfill', 'bfill', 'ffill',
71117111
# 'pad']]"; expected "Literal['ffill', 'bfill', 'pad', 'backfill']"
71127112
method, # type: ignore[arg-type]
@@ -7311,7 +7311,7 @@ def ffill(
73117311
"""
73127312
self._deprecate_downcast(downcast)
73137313

7314-
return self._fillna_with_method(
7314+
return self._pad_or_backfill(
73157315
"ffill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
73167316
)
73177317

@@ -7443,7 +7443,7 @@ def bfill(
74437443
3 4.0 7
74447444
"""
74457445
self._deprecate_downcast(downcast)
7446-
return self._fillna_with_method(
7446+
return self._pad_or_backfill(
74477447
"bfill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
74487448
)
74497449

@@ -8003,22 +8003,27 @@ def interpolate(
80038003
"column to a numeric dtype."
80048004
)
80058005

8006-
index = missing.get_interp_index(method, obj.index)
8006+
if "fill_value" in kwargs:
8007+
raise ValueError(
8008+
"'fill_value' is not a valid keyword for "
8009+
f"{type(self).__name__}.interpolate"
8010+
)
80078011

80088012
if method.lower() in fillna_methods:
80098013
# TODO(3.0): remove this case
8014+
# TODO: warn/raise on limit_direction or kwargs which are ignored?
8015+
# as of 2023-06-26 no tests get here with either
8016+
80108017
new_data = obj._mgr.pad_or_backfill(
80118018
method=method,
80128019
axis=axis,
8013-
index=index,
80148020
limit=limit,
8015-
limit_direction=limit_direction,
80168021
limit_area=limit_area,
80178022
inplace=inplace,
80188023
downcast=downcast,
8019-
**kwargs,
80208024
)
80218025
else:
8026+
index = missing.get_interp_index(method, obj.index)
80228027
axis = self._info_axis_number
80238028
new_data = obj._mgr.interpolate(
80248029
method=method,
@@ -9980,8 +9985,8 @@ def _align_frame(
99809985
)
99819986

99829987
if method is not None:
9983-
left = left._fillna_with_method(method, axis=fill_axis, limit=limit)
9984-
right = right._fillna_with_method(method, axis=fill_axis, limit=limit)
9988+
left = left._pad_or_backfill(method, axis=fill_axis, limit=limit)
9989+
right = right._pad_or_backfill(method, axis=fill_axis, limit=limit)
99859990

99869991
return left, right, join_index
99879992

@@ -10057,8 +10062,8 @@ def _align_series(
1005710062
if fill_na:
1005810063
fill_value, method = validate_fillna_kwargs(fill_value, method)
1005910064
if method is not None:
10060-
left = left._fillna_with_method(method, limit=limit, axis=fill_axis)
10061-
right = right._fillna_with_method(method, limit=limit)
10065+
left = left._pad_or_backfill(method, limit=limit, axis=fill_axis)
10066+
right = right._pad_or_backfill(method, limit=limit)
1006210067
else:
1006310068
left = left.fillna(fill_value, limit=limit, axis=fill_axis)
1006410069
right = right.fillna(fill_value, limit=limit)
@@ -11474,7 +11479,7 @@ def pct_change(
1147411479
if fill_method is None:
1147511480
data = self
1147611481
else:
11477-
data = self._fillna_with_method(fill_method, axis=axis, limit=limit)
11482+
data = self._pad_or_backfill(fill_method, axis=axis, limit=limit)
1147811483

1147911484
shifted = data.shift(periods=periods, freq=freq, axis=axis, **kwargs)
1148011485
# Unsupported left operand type for / ("Self")

pandas/core/internals/blocks.py

-13
Original file line numberDiff line numberDiff line change
@@ -1348,25 +1348,19 @@ def pad_or_backfill(
13481348
*,
13491349
method: FillnaOptions = "pad",
13501350
axis: AxisInt = 0,
1351-
index: Index | None = None,
13521351
inplace: bool = False,
13531352
limit: int | None = None,
1354-
limit_direction: Literal["forward", "backward", "both"] = "forward",
13551353
limit_area: Literal["inside", "outside"] | None = None,
1356-
fill_value: Any | None = None,
13571354
downcast: Literal["infer"] | None = None,
13581355
using_cow: bool = False,
13591356
**kwargs,
13601357
) -> list[Block]:
13611358
return self.interpolate(
13621359
method=method,
13631360
axis=axis,
1364-
index=index,
13651361
inplace=inplace,
13661362
limit=limit,
1367-
limit_direction=limit_direction,
13681363
limit_area=limit_area,
1369-
fill_value=fill_value,
13701364
downcast=downcast,
13711365
using_cow=using_cow,
13721366
**kwargs,
@@ -1382,7 +1376,6 @@ def interpolate(
13821376
limit: int | None = None,
13831377
limit_direction: Literal["forward", "backward", "both"] = "forward",
13841378
limit_area: Literal["inside", "outside"] | None = None,
1385-
fill_value: Any | None = None,
13861379
downcast: Literal["infer"] | None = None,
13871380
using_cow: bool = False,
13881381
**kwargs,
@@ -1424,7 +1417,6 @@ def interpolate(
14241417
limit=limit,
14251418
limit_direction=limit_direction,
14261419
limit_area=limit_area,
1427-
fill_value=fill_value,
14281420
downcast=downcast,
14291421
**kwargs,
14301422
)
@@ -1440,10 +1432,6 @@ def interpolate(
14401432
# Dispatch to the PandasArray method.
14411433
# We know self.array_values is a PandasArray bc EABlock overrides
14421434
if m is not None:
1443-
if fill_value is not None:
1444-
# similar to validate_fillna_kwargs
1445-
raise ValueError("Cannot pass both fill_value and method")
1446-
14471435
# TODO: warn about ignored kwargs, limit_direction, index...?
14481436
new_values = cast(PandasArray, self.array_values).pad_or_backfill(
14491437
method=method,
@@ -1461,7 +1449,6 @@ def interpolate(
14611449
limit=limit,
14621450
limit_direction=limit_direction,
14631451
limit_area=limit_area,
1464-
fill_value=fill_value,
14651452
inplace=arr_inplace,
14661453
**kwargs,
14671454
)

pandas/tests/series/methods/test_interpolate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def test_interp_invalid_method_and_value(self):
361361
# GH#36624
362362
ser = Series([1, 3, np.nan, 12, np.nan, 25])
363363

364-
msg = "Cannot pass both fill_value and method"
364+
msg = "'fill_value' is not a valid keyword for Series.interpolate"
365365
msg2 = "Series.interpolate with method=pad"
366366
with pytest.raises(ValueError, match=msg):
367367
with tm.assert_produces_warning(FutureWarning, match=msg2):

0 commit comments

Comments
 (0)