Skip to content

Commit 43a734e

Browse files
committed
TST: Add test for groupby sum of large ints
Closes gh-14758.
1 parent 18a428d commit 43a734e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/tests/groupby/test_aggregate.py

+30
Original file line numberDiff line numberDiff line change
@@ -844,3 +844,33 @@ def test_agg_timezone_round_trip(self):
844844
ts = df['B'].iloc[2]
845845
assert ts == grouped.last()['B'].iloc[0]
846846
assert ts == grouped.apply(lambda x: x.iloc[-1])[0]
847+
848+
def test_sum_uint64_overflow(self):
849+
# see gh-14758
850+
851+
# Convert to uint64
852+
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]],
853+
dtype=object) + 9223372036854775807
854+
855+
index = pd.Index([9223372036854775808, 9223372036854775810,
856+
9223372036854775812], dtype=np.uint64)
857+
expected = pd.DataFrame({1: [9223372036854775809,
858+
9223372036854775811,
859+
9223372036854775813]}, index=index)
860+
861+
expected.index.name = 0
862+
result = df.groupby(0).sum()
863+
tm.assert_frame_equal(result, expected)
864+
865+
# Remain as object
866+
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]],
867+
dtype=object) + 19223372036854775807
868+
869+
index = pd.Index([19223372036854775808, 19223372036854775810,
870+
19223372036854775812], dtype=object)
871+
expected = pd.DataFrame({1: [19223372036854775809,
872+
19223372036854775811,
873+
19223372036854775813]}, index=index)
874+
expected.index.name = 0
875+
result = df.groupby(0).sum()
876+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)