def nunique(self, dropna=True):
ids, _, _ = self.grouper.group_info<EOL>val = self.obj.get_values()<EOL>try:<EOL><INDENT>sorter = np.lexsort((val, ids))<EOL><DEDENT>except TypeError:  <EOL><INDENT>msg = '<STR_LIT>'.format(val.dtype)<EOL>assert val.dtype == object, msg<EOL>val, _ = algorithms.factorize(val, sort=False)<EOL>sorter = np.lexsort((val, ids))<EOL>_isna = lambda a: a == -<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>_isna = isna<EOL><DEDENT>ids, val = ids[sorter], val[sorter]<EOL>idx = np.r_[<NUM_LIT:0>, <NUM_LIT:1> + np.nonzero(ids[<NUM_LIT:1>:] != ids[:-<NUM_LIT:1>])[<NUM_LIT:0>]]<EOL>inc = np.r_[<NUM_LIT:1>, val[<NUM_LIT:1>:] != val[:-<NUM_LIT:1>]]<EOL>mask = _isna(val)<EOL>if dropna:<EOL><INDENT>inc[idx] = <NUM_LIT:1><EOL>inc[mask] = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>inc[mask & np.r_[False, mask[:-<NUM_LIT:1>]]] = <NUM_LIT:0><EOL>inc[idx] = <NUM_LIT:1><EOL><DEDENT>out = np.add.reduceat(inc, idx).astype('<STR_LIT>', copy=False)<EOL>if len(ids):<EOL><INDENT>if ids[<NUM_LIT:0>] == -<NUM_LIT:1>:<EOL><INDENT>res = out[<NUM_LIT:1>:]<EOL>idx = idx[np.flatnonzero(idx)]<EOL><DEDENT>else:<EOL><INDENT>res = out<EOL><DEDENT><DEDENT>else:<EOL><INDENT>res = out[<NUM_LIT:1>:]<EOL><DEDENT>ri = self.grouper.result_index<EOL>if len(res) != len(ri):<EOL><INDENT>res, out = np.zeros(len(ri), dtype=out.dtype), res<EOL>res[ids[idx]] = out<EOL><DEDENT>return Series(res,<EOL>index=ri,<EOL>name=self._selection_name)<EOL>
Return number of unique elements in the group.