Add count and count_by_group methods.