Performance improvements for nunique method. ref pydata/pandas#7771