Skip to content

Commit d2a062b

Browse files
committed
Added test_sum_string_dtype_coercion that checks summing numeric strings results in concatenation and not coercion to dtype int64 or float64
1 parent 1a3230d commit d2a062b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/frame/test_reductions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,25 @@ def test_sum_bools(self):
10431043
bools = isna(df)
10441044
assert bools.sum(axis=1)[0] == 10
10451045

1046+
def test_sum_string_dtype_coercion(self):
1047+
# GH#22642
1048+
# Check that summing numeric strings results in concatenation
1049+
# and not conversion to dtype int64 or float64
1050+
df = DataFrame({"a": ["483", "3"], "b": ["94", "759"]})
1051+
result = df.sum(axis=1)
1052+
expected = Series(["48394", "3759"])
1053+
tm.assert_series_equal(result, expected)
1054+
1055+
df = DataFrame({"a": ["483.948", "3.0"], "b": ["94.2", "759.93"]})
1056+
result = df.sum(axis=1)
1057+
expected = Series(["483.94894.2", "3.0759.93"])
1058+
tm.assert_series_equal(result, expected)
1059+
1060+
df = DataFrame({"a": ["483", "3.0"], "b": ["94.2", "79"]})
1061+
result = df.sum(axis=1)
1062+
expected = Series(["48394.2", "3.079"])
1063+
tm.assert_series_equal(result, expected)
1064+
10461065
# ----------------------------------------------------------------------
10471066
# Index of max / min
10481067

0 commit comments

Comments
 (0)