Skip to content

Commit 1553d23

Browse files
committed
TST: add regression test for GH#14407 fillna numeric conversion
1 parent c3a4ffc commit 1553d23

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/frame/methods/test_fillna.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Timestamp,
1515
date_range,
1616
to_datetime,
17+
to_numeric,
1718
)
1819
import pandas._testing as tm
1920
from pandas.tests.frame.common import _check_mixed_float
@@ -670,6 +671,26 @@ def test_fillna_with_multi_index_frame(self):
670671
)
671672
tm.assert_frame_equal(pdf.fillna({("x", "b"): -2, "x": -1}), expected)
672673

674+
def test_fillna_preserves_numeric_conversion(self):
675+
# GH#14407 regression test
676+
df = DataFrame(
677+
{
678+
"c1": ["A", "B", "C"],
679+
"c2": ["1", "2", "3"],
680+
"c3": [0.1, 0.2, 0.3],
681+
"c4": [0, 1, 2],
682+
}
683+
)
684+
685+
result = df.apply(lambda x: to_numeric(x, errors="coerce")).fillna(df)
686+
687+
expected = Series(
688+
{"c1": "object", "c2": "int64", "c3": "float64", "c4": "int64"},
689+
name="dtype",
690+
)
691+
692+
assert result.dtypes.astype(str).equals(expected)
693+
673694

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

0 commit comments

Comments
 (0)