Skip to content

Commit b4b35af

Browse files
committed
REF: swap axis before calling Manager.pad_or_backfill
1 parent 866a388 commit b4b35af

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

pandas/core/arrays/numpy_.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6911,7 +6911,7 @@ def _pad_or_backfill(
69116911

69126912
new_mgr = self._mgr.pad_or_backfill(
69136913
method=method,
6914-
axis=axis,
6914+
axis=self._get_block_manager_axis(axis),
69156915
limit=limit,
69166916
inplace=inplace,
69176917
downcast=downcast,
@@ -8027,7 +8027,7 @@ def interpolate(
80278027

80288028
new_data = obj._mgr.pad_or_backfill(
80298029
method=method,
8030-
axis=axis,
8030+
axis=self._get_block_manager_axis(axis),
80318031
limit=limit,
80328032
limit_area=limit_area,
80338033
inplace=inplace,

pandas/core/internals/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,8 +1901,8 @@ def pad_or_backfill(
19011901
using_cow: bool = False,
19021902
) -> list[Block]:
19031903
values = self.values
1904-
if values.ndim == 2 and axis == 0:
1905-
# NDArrayBackedExtensionArray.fillna assumes axis=1
1904+
if values.ndim == 2 and axis == 1:
1905+
# NDArrayBackedExtensionArray.fillna assumes axis=0
19061906
new_values = values.T.fillna(method=method, limit=limit).T
19071907
else:
19081908
new_values = values.fillna(method=method, limit=limit)

pandas/tests/extension/base/dim2.py

Lines changed: 17 additions & 1 deletion
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)