there needs to be a check whether the user specified a comparison_name that is in groupsunique. and raise a ValueError if not.
midx empty,  np.size(midx) == 0 ?

I mistyped and got a misleading exception further down.