diff --git a/pandas/tests/frame/test_reductions.py b/pandas/tests/frame/test_reductions.py index 4d8f163197416..ddce4be070e7b 100644 --- a/pandas/tests/frame/test_reductions.py +++ b/pandas/tests/frame/test_reductions.py @@ -1043,6 +1043,30 @@ def test_sum_bools(self): bools = isna(df) assert bools.sum(axis=1)[0] == 10 + @pytest.mark.parametrize( + "df, expected", + [ + ( + DataFrame({"a": ["483", "3"], "b": ["94", "759"]}), + Series(["48394", "3759"]), + ), + ( + DataFrame({"a": ["483.948", "3.0"], "b": ["94.2", "759.93"]}), + Series(["483.94894.2", "3.0759.93"]), + ), + ( + DataFrame({"a": ["483", "3.0"], "b": ["94.2", "79"]}), + Series(["48394.2", "3.079"]), + ), + ], + ) + def test_sum_string_dtype_coercion(self, df, expected): + # GH#22642 + # Check that summing numeric strings results in concatenation + # and not conversion to dtype int64 or float64 + result = df.sum(axis=1) + tm.assert_series_equal(result, expected) + # ---------------------------------------------------------------------- # Index of max / min