From 78da928822c57130939896c96db4446f570c555f Mon Sep 17 00:00:00 2001 From: skalwaghe-56 Date: Sun, 7 Sep 2025 21:53:56 +0530 Subject: [PATCH] TST: add regression test for GH#14407 fillna numeric conversion --- pandas/tests/frame/methods/test_fillna.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 8915d6f205d65..8bb369169003b 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -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 @@ -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