ENH use np.unique instead of groupby