Instead of hard coding the _count, _sum etc, why not make merged a dictionary where the keys are 'raw', 'sum', 'count' etc. That way its easy to extend it later on to add new aggregation stats like 'p50', 'p99' etc.