Revert "Rewrite as a comprehension, as suggested by Harlan."

This reverts commit 383d8f65f106969aa9186db0f42daa6641f8fee8.
Revert "Bugfix: fix overflow in groupby"

This reverts commit a300c3832a0ae17588f6996adfe9e21e358767ed.