Skip to content

Commit 0a8b45f

Browse files
authored
BUG: df.fillna ignores axis when df is single block (#47714)
* Update generic.py * Update test_fillna.py * Update v1.5.0.rst * fix array format * fix what's new description * fix format * Update test_fillna.py
1 parent a7b8c1d commit 0a8b45f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ Missing
914914
- Bug in :meth:`Series.fillna` and :meth:`DataFrame.fillna` with :class:`IntervalDtype` and incompatible value raising instead of casting to a common (usually object) dtype (:issue:`45796`)
915915
- Bug in :meth:`DataFrame.interpolate` with object-dtype column not returning a copy with ``inplace=False`` (:issue:`45791`)
916916
- Bug in :meth:`DataFrame.dropna` allows to set both ``how`` and ``thresh`` incompatible arguments (:issue:`46575`)
917+
- Bug in :meth:`DataFrame.fillna` ignored ``axis`` when :class:`DataFrame` is single block (:issue:`47713`)
917918

918919
MultiIndex
919920
^^^^^^^^^^

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6679,7 +6679,7 @@ def fillna(
66796679
return result if not inplace else None
66806680

66816681
elif not is_list_like(value):
6682-
if not self._mgr.is_single_block and axis == 1:
6682+
if axis == 1:
66836683

66846684
result = self.T.fillna(value=value, limit=limit).T
66856685

pandas/tests/frame/methods/test_fillna.py

+23
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,29 @@ def test_inplace_dict_update_view(self, val):
685685
tm.assert_frame_equal(df, expected)
686686
tm.assert_frame_equal(result_view, expected)
687687

688+
def test_single_block_df_with_horizontal_axis(self):
689+
# GH 47713
690+
df = DataFrame(
691+
{
692+
"col1": [5, 0, np.nan, 10, np.nan],
693+
"col2": [7, np.nan, np.nan, 5, 3],
694+
"col3": [12, np.nan, 1, 2, 0],
695+
"col4": [np.nan, 1, 1, np.nan, 18],
696+
}
697+
)
698+
result = df.fillna(50, limit=1, axis=1)
699+
expected = DataFrame(
700+
[
701+
[5.0, 7.0, 12.0, 50.0],
702+
[0.0, 50.0, np.nan, 1.0],
703+
[50.0, np.nan, 1.0, 1.0],
704+
[10.0, 5.0, 2.0, 50.0],
705+
[50.0, 3.0, 0.0, 18.0],
706+
],
707+
columns=["col1", "col2", "col3", "col4"],
708+
)
709+
tm.assert_frame_equal(result, expected)
710+
688711

689712
def test_fillna_nonconsolidated_frame():
690713
# https://github.com/pandas-dev/pandas/issues/36495

0 commit comments

Comments
 (0)