Skip to content

Commit f217bf9

Browse files
jbrockmendelim-vinicius
authored and
im-vinicius
committed
REF: swap axis before calling Manager.pad_or_backfill (pandas-dev#53989)
1 parent 130471e commit f217bf9

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

pandas/core/arrays/numpy_.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def pad_or_backfill(
247247

248248
meth = missing.clean_fill_method(method)
249249
missing.pad_or_backfill_inplace(
250-
out_data,
250+
out_data.T,
251251
method=meth,
252252
axis=0,
253253
limit=limit,

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6917,7 +6917,7 @@ def _pad_or_backfill(
69176917

69186918
new_mgr = self._mgr.pad_or_backfill(
69196919
method=method,
6920-
axis=axis,
6920+
axis=self._get_block_manager_axis(axis),
69216921
limit=limit,
69226922
inplace=inplace,
69236923
downcast=downcast,
@@ -8043,7 +8043,7 @@ def interpolate(
80438043

80448044
new_data = obj._mgr.pad_or_backfill(
80458045
method=method,
8046-
axis=axis,
8046+
axis=self._get_block_manager_axis(axis),
80478047
limit=limit,
80488048
limit_area=limit_area,
80498049
inplace=inplace,

pandas/core/internals/blocks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1885,8 +1885,8 @@ def pad_or_backfill(
18851885
using_cow: bool = False,
18861886
) -> list[Block]:
18871887
values = self.values
1888-
if values.ndim == 2 and axis == 0:
1889-
# NDArrayBackedExtensionArray.fillna assumes axis=1
1888+
if values.ndim == 2 and axis == 1:
1889+
# NDArrayBackedExtensionArray.fillna assumes axis=0
18901890
new_values = values.T.fillna(method=method, limit=limit).T
18911891
else:
18921892
new_values = values.fillna(method=method, limit=limit)

pandas/tests/extension/base/dim2.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,27 @@ def test_fillna_2d_method(self, data_missing, method):
159159
assert arr[0].isna().all()
160160
assert not arr[1].isna().any()
161161

162-
result = arr.fillna(method=method)
162+
try:
163+
result = arr.pad_or_backfill(method=method, limit=None)
164+
except AttributeError:
165+
result = arr.fillna(method=method, limit=None)
163166

164167
expected = data_missing.fillna(method=method).repeat(2).reshape(2, 2)
165168
self.assert_extension_array_equal(result, expected)
166169

170+
# Reverse so that backfill is not a no-op.
171+
arr2 = arr[::-1]
172+
assert not arr2[0].isna().any()
173+
assert arr2[1].isna().all()
174+
175+
try:
176+
result2 = arr2.pad_or_backfill(method=method, limit=None)
177+
except AttributeError:
178+
result2 = arr2.fillna(method=method, limit=None)
179+
180+
expected2 = data_missing[::-1].fillna(method=method).repeat(2).reshape(2, 2)
181+
self.assert_extension_array_equal(result2, expected2)
182+
167183
@pytest.mark.parametrize("method", ["mean", "median", "var", "std", "sum", "prod"])
168184
def test_reductions_2d_axis_none(self, data, method):
169185
arr2d = data.reshape(1, -1)

0 commit comments

Comments
 (0)