BUG: add sanity check to groupby agg function, outside main loop