Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use pytest.mark.parametrize like

@pytest.mark.parametrize("input_data,expected_data", [[{"a": ...}, ["48394" ...]] ,...])

so we don't have to repeat 3 separate setups?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can. I will make these changes tonight and resubmit.

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

Expand Down
Loading