From d2a062b79bcedc910534eefb86a100c9dbffa92e Mon Sep 17 00:00:00 2001 From: AbelJSanchez Date: Wed, 3 Dec 2025 21:55:39 -0800 Subject: [PATCH] Added test_sum_string_dtype_coercion that checks summing numeric strings results in concatenation and not coercion to dtype int64 or float64 --- pandas/tests/frame/test_reductions.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 4d8f163197416..0cb60bca8ee66 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1043,6 +1043,25 @@ def test_sum_bools(self): bools = isna(df) assert bools.sum(axis=1)[0] == 10 + def test_sum_string_dtype_coercion(self): + # GH#22642 + # Check that summing numeric strings results in concatenation + # and not conversion to dtype int64 or float64 + df = DataFrame({"a": ["483", "3"], "b": ["94", "759"]}) + result = df.sum(axis=1) + expected = Series(["48394", "3759"]) + tm.assert_series_equal(result, expected) + + df = DataFrame({"a": ["483.948", "3.0"], "b": ["94.2", "759.93"]}) + result = df.sum(axis=1) + expected = Series(["483.94894.2", "3.0759.93"]) + tm.assert_series_equal(result, expected) + + df = DataFrame({"a": ["483", "3.0"], "b": ["94.2", "79"]}) + result = df.sum(axis=1) + expected = Series(["48394.2", "3.079"]) + tm.assert_series_equal(result, expected) + # ---------------------------------------------------------------------- # Index of max / min