Skip to content

Commit 8be8439

Browse files
authored
TST: Added test that checks if df.sum() results in concatenation instead of dtype coercion to float64 or int64 (#63260)
1 parent e450f0c commit 8be8439

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/frame/test_reductions.py

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

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

0 commit comments

Comments
 (0)