Skip to content
Closed
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
21 changes: 21 additions & 0 deletions pandas/tests/frame/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Timestamp,
date_range,
to_datetime,
to_numeric,
)
import pandas._testing as tm
from pandas.tests.frame.common import _check_mixed_float
Expand Down Expand Up @@ -670,6 +671,26 @@ def test_fillna_with_multi_index_frame(self):
)
tm.assert_frame_equal(pdf.fillna({("x", "b"): -2, "x": -1}), expected)

def test_fillna_preserves_numeric_conversion(self):
# GH#14407 regression test
df = DataFrame(
{
"c1": ["A", "B", "C"],
"c2": ["1", "2", "3"],
"c3": [0.1, 0.2, 0.3],
"c4": [0, 1, 2],
}
)

result = df.apply(lambda x: to_numeric(x, errors="coerce")).fillna(df)

expected = Series(
{"c1": "object", "c2": "int64", "c3": "float64", "c4": "int64"},
name="dtype",
)

assert result.dtypes.astype(str).equals(expected)


def test_fillna_nonconsolidated_frame():
# https://github.com/pandas-dev/pandas/issues/36495
Expand Down
Loading