Skip to content

CLN: unused args in pad_or_backfill #53872

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 3 commits into from
Jun 27, 2023
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
2 changes: 0 additions & 2 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,6 @@ def interpolate(
limit,
limit_direction,
limit_area,
fill_value,
inplace: bool,
**kwargs,
) -> Self:
Expand All @@ -2263,7 +2262,6 @@ def interpolate(
limit=limit,
limit_direction=limit_direction,
limit_area=limit_area,
fill_value=fill_value,
**kwargs,
)
if inplace:
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ def interpolate(
limit,
limit_direction,
limit_area,
fill_value,
inplace: bool,
**kwargs,
) -> Self:
Expand All @@ -289,7 +288,6 @@ def interpolate(
limit=limit,
limit_direction=limit_direction,
limit_area=limit_area,
fill_value=fill_value,
**kwargs,
)
if inplace:
Expand Down
35 changes: 20 additions & 15 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6891,7 +6891,7 @@ def _deprecate_downcast(self, downcast) -> None:
)

@final
def _fillna_with_method(
def _pad_or_backfill(
self,
method: Literal["ffill", "bfill", "pad", "backfill"],
*,
Expand All @@ -6908,7 +6908,7 @@ def _fillna_with_method(
if not self._mgr.is_single_block and axis == 1:
if inplace:
raise NotImplementedError()
result = self.T._fillna_with_method(method=method, limit=limit).T
result = self.T._pad_or_backfill(method=method, limit=limit).T

return result

Expand Down Expand Up @@ -7105,8 +7105,8 @@ def fillna(
axis = self._get_axis_number(axis)

if value is None:
return self._fillna_with_method(
# error: Argument 1 to "_fillna_with_method" of "NDFrame" has
return self._pad_or_backfill(
# error: Argument 1 to "_pad_or_backfill" of "NDFrame" has
# incompatible type "Optional[Literal['backfill', 'bfill', 'ffill',
# 'pad']]"; expected "Literal['ffill', 'bfill', 'pad', 'backfill']"
method, # type: ignore[arg-type]
Expand Down Expand Up @@ -7311,7 +7311,7 @@ def ffill(
"""
self._deprecate_downcast(downcast)

return self._fillna_with_method(
return self._pad_or_backfill(
"ffill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
)

Expand Down Expand Up @@ -7443,7 +7443,7 @@ def bfill(
3 4.0 7
"""
self._deprecate_downcast(downcast)
return self._fillna_with_method(
return self._pad_or_backfill(
"bfill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
)

Expand Down Expand Up @@ -8003,22 +8003,27 @@ def interpolate(
"column to a numeric dtype."
)

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

if method.lower() in fillna_methods:
# TODO(3.0): remove this case
# TODO: warn/raise on limit_direction or kwargs which are ignored?
# as of 2023-06-26 no tests get here with either

new_data = obj._mgr.pad_or_backfill(
method=method,
axis=axis,
index=index,
limit=limit,
limit_direction=limit_direction,
limit_area=limit_area,
inplace=inplace,
downcast=downcast,
**kwargs,
)
else:
index = missing.get_interp_index(method, obj.index)
axis = self._info_axis_number
new_data = obj._mgr.interpolate(
method=method,
Expand Down Expand Up @@ -9980,8 +9985,8 @@ def _align_frame(
)

if method is not None:
left = left._fillna_with_method(method, axis=fill_axis, limit=limit)
right = right._fillna_with_method(method, axis=fill_axis, limit=limit)
left = left._pad_or_backfill(method, axis=fill_axis, limit=limit)
right = right._pad_or_backfill(method, axis=fill_axis, limit=limit)

return left, right, join_index

Expand Down Expand Up @@ -10057,8 +10062,8 @@ def _align_series(
if fill_na:
fill_value, method = validate_fillna_kwargs(fill_value, method)
if method is not None:
left = left._fillna_with_method(method, limit=limit, axis=fill_axis)
right = right._fillna_with_method(method, limit=limit)
left = left._pad_or_backfill(method, limit=limit, axis=fill_axis)
right = right._pad_or_backfill(method, limit=limit)
else:
left = left.fillna(fill_value, limit=limit, axis=fill_axis)
right = right.fillna(fill_value, limit=limit)
Expand Down Expand Up @@ -11474,7 +11479,7 @@ def pct_change(
if fill_method is None:
data = self
else:
data = self._fillna_with_method(fill_method, axis=axis, limit=limit)
data = self._pad_or_backfill(fill_method, axis=axis, limit=limit)

shifted = data.shift(periods=periods, freq=freq, axis=axis, **kwargs)
# Unsupported left operand type for / ("Self")
Expand Down
13 changes: 0 additions & 13 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,25 +1348,19 @@ def pad_or_backfill(
*,
method: FillnaOptions = "pad",
axis: AxisInt = 0,
index: Index | None = None,
inplace: bool = False,
limit: int | None = None,
limit_direction: Literal["forward", "backward", "both"] = "forward",
limit_area: Literal["inside", "outside"] | None = None,
fill_value: Any | None = None,
downcast: Literal["infer"] | None = None,
using_cow: bool = False,
**kwargs,
) -> list[Block]:
return self.interpolate(
method=method,
axis=axis,
index=index,
inplace=inplace,
limit=limit,
limit_direction=limit_direction,
limit_area=limit_area,
fill_value=fill_value,
downcast=downcast,
using_cow=using_cow,
**kwargs,
Expand All @@ -1382,7 +1376,6 @@ def interpolate(
limit: int | None = None,
limit_direction: Literal["forward", "backward", "both"] = "forward",
limit_area: Literal["inside", "outside"] | None = None,
fill_value: Any | None = None,
downcast: Literal["infer"] | None = None,
using_cow: bool = False,
**kwargs,
Expand Down Expand Up @@ -1424,7 +1417,6 @@ def interpolate(
limit=limit,
limit_direction=limit_direction,
limit_area=limit_area,
fill_value=fill_value,
downcast=downcast,
**kwargs,
)
Expand All @@ -1440,10 +1432,6 @@ def interpolate(
# Dispatch to the PandasArray method.
# We know self.array_values is a PandasArray bc EABlock overrides
if m is not None:
if fill_value is not None:
# similar to validate_fillna_kwargs
raise ValueError("Cannot pass both fill_value and method")

# TODO: warn about ignored kwargs, limit_direction, index...?
new_values = cast(PandasArray, self.array_values).pad_or_backfill(
method=method,
Expand All @@ -1461,7 +1449,6 @@ def interpolate(
limit=limit,
limit_direction=limit_direction,
limit_area=limit_area,
fill_value=fill_value,
inplace=arr_inplace,
**kwargs,
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/methods/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def test_interp_invalid_method_and_value(self):
# GH#36624
ser = Series([1, 3, np.nan, 12, np.nan, 25])

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