Skip to content

Commit 309ecac

Browse files
committed
TST: Add test for groupby sum of large ints
Closes gh-14758.
1 parent d915c7e commit 309ecac

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Diff for: pandas/tests/groupby/test_aggregate.py

+32
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,35 @@ def test_agg_timezone_round_trip(self):
865865
ts = df['B'].iloc[2]
866866
assert ts == grouped.last()['B'].iloc[0]
867867
assert ts == grouped.apply(lambda x: x.iloc[-1])[0]
868+
869+
def test_sum_uint64_overflow(self):
870+
# see gh-14758
871+
872+
# Convert to uint64
873+
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]],
874+
dtype=object) + 9223372036854775807
875+
876+
index = pd.Index([9223372036854775808, 9223372036854775810,
877+
9223372036854775812], dtype=np.uint64)
878+
expected = pd.DataFrame({1: [9223372036854775809,
879+
9223372036854775811,
880+
9223372036854775813]}, index=index)
881+
882+
expected.index.name = 0
883+
result = df.groupby(0).sum()
884+
tm.assert_frame_equal(result, expected)
885+
886+
# Remain as object
887+
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]],
888+
dtype=object) + 19223372036854775807
889+
890+
index = pd.Index([19223372036854775808, 19223372036854775810,
891+
19223372036854775812], dtype=object)
892+
expected = pd.DataFrame({1: [19223372036854775809,
893+
19223372036854775811,
894+
19223372036854775813]},
895+
dtype=object, index=index)
896+
897+
expected.index.name = 0
898+
result = df.groupby(0).sum()
899+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)