Skip to content

CLN: remove axis keyword from Block.pad_or_backill #58038

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 1 commit into from
Mar 28, 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
9 changes: 3 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6727,12 +6727,10 @@ def _pad_or_backfill(
axis = self._get_axis_number(axis)
method = clean_fill_method(method)

if not self._mgr.is_single_block and axis == 1:
# e.g. test_align_fill_method
# TODO(3.0): once downcast is removed, we can do the .T
# in all axis=1 cases, and remove axis kward from mgr.pad_or_backfill.
if inplace:
if axis == 1:
if not self._mgr.is_single_block and inplace:
raise NotImplementedError()
# e.g. test_align_fill_method
result = self.T._pad_or_backfill(
method=method, limit=limit, limit_area=limit_area
).T
Expand All @@ -6741,7 +6739,6 @@ def _pad_or_backfill(

new_mgr = self._mgr.pad_or_backfill(
method=method,
axis=self._get_block_manager_axis(axis),
limit=limit,
limit_area=limit_area,
inplace=inplace,
Expand Down
14 changes: 4 additions & 10 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,6 @@ def pad_or_backfill(
self,
*,
method: FillnaOptions,
axis: AxisInt = 0,
inplace: bool = False,
limit: int | None = None,
limit_area: Literal["inside", "outside"] | None = None,
Expand All @@ -1357,16 +1356,12 @@ def pad_or_backfill(
# Dispatch to the NumpyExtensionArray method.
# We know self.array_values is a NumpyExtensionArray bc EABlock overrides
vals = cast(NumpyExtensionArray, self.array_values)
if axis == 1:
vals = vals.T
new_values = vals._pad_or_backfill(
new_values = vals.T._pad_or_backfill(
method=method,
limit=limit,
limit_area=limit_area,
copy=copy,
)
if axis == 1:
new_values = new_values.T
).T

data = extract_array(new_values, extract_numpy=True)
return [self.make_block_same_class(data, refs=refs)]
Expand Down Expand Up @@ -1814,7 +1809,6 @@ def pad_or_backfill(
self,
*,
method: FillnaOptions,
axis: AxisInt = 0,
inplace: bool = False,
limit: int | None = None,
limit_area: Literal["inside", "outside"] | None = None,
Expand All @@ -1827,11 +1821,11 @@ def pad_or_backfill(
elif limit_area is not None:
raise NotImplementedError(
f"{type(values).__name__} does not implement limit_area "
"(added in pandas 2.2). 3rd-party ExtnsionArray authors "
"(added in pandas 2.2). 3rd-party ExtensionArray authors "
"need to add this argument to _pad_or_backfill."
)

if values.ndim == 2 and axis == 1:
if values.ndim == 2:
# NDArrayBackedExtensionArray.fillna assumes axis=0
new_values = values.T._pad_or_backfill(**kwargs).T
else:
Expand Down