From 309b6a062c44cace2e09a9feae21eee5a6320da3 Mon Sep 17 00:00:00 2001 From: Brandon Norton Date: Thu, 8 Feb 2024 14:18:53 -0500 Subject: [PATCH 1/2] add a test to check signedness preservation after sum --- pandas/tests/reductions/test_reductions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 20749c7ed90e8..55635ca220ece 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -1259,6 +1259,17 @@ def test_sum_uint64(self): expected = np.uint64(10000000000000000000) tm.assert_almost_equal(result, expected) + def test_signedness_preserved_after_sum(self): + s = Series([1, 2, 3, 4]) + + result1 = s.astype("int8").sum().dtype + result2 = s.astype("uint8").sum().dtype + expected1 = "int64" + expected2 = "uint64" + + assert result1 == expected1 + assert result2 == expected2 + class TestDatetime64SeriesReductions: # Note: the name TestDatetime64SeriesReductions indicates these tests From 2581a753f10c2b2403a2909c222ffbb703e9d33c Mon Sep 17 00:00:00 2001 From: Brandon Norton Date: Thu, 8 Feb 2024 17:29:11 -0500 Subject: [PATCH 2/2] removed test for int8 and added issue number --- pandas/tests/reductions/test_reductions.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 55635ca220ece..efecd43625eed 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -1260,15 +1260,10 @@ def test_sum_uint64(self): tm.assert_almost_equal(result, expected) def test_signedness_preserved_after_sum(self): - s = Series([1, 2, 3, 4]) + # GH 37491 + ser = Series([1, 2, 3, 4]) - result1 = s.astype("int8").sum().dtype - result2 = s.astype("uint8").sum().dtype - expected1 = "int64" - expected2 = "uint64" - - assert result1 == expected1 - assert result2 == expected2 + assert ser.astype("uint8").sum().dtype == "uint64" class TestDatetime64SeriesReductions: