def unique(self):
<EOL>unique_codes = unique1d(self.codes)<EOL>cat = self.copy()<EOL>cat._codes = unique_codes<EOL>take_codes = unique_codes[unique_codes != -<NUM_LIT:1>]<EOL>if self.ordered:<EOL><INDENT>take_codes = np.sort(take_codes)<EOL><DEDENT>return cat.set_categories(cat.categories.take(take_codes))<EOL>
Return the ``Categorical`` which ``categories`` and ``codes`` are
unique. Unused categories are NOT returned.

- unordered category: values and categories are sorted by appearance
  order.
- ordered category: values are sorted by appearance order, categories
  keeps existing order.

Returns
-------
unique values : ``Categorical``

Examples
--------
An unordered Categorical will return categories in the
order of appearance.

>>> pd.Categorical(list('baabc'))
[b, a, c]
Categories (3, object): [b, a, c]

>>> pd.Categorical(list('baabc'), categories=list('abc'))
[b, a, c]
Categories (3, object): [b, a, c]

An ordered Categorical preserves the category ordering.

>>> pd.Categorical(list('baabc'),
...                categories=list('abc'),
...                ordered=True)
[b, a, c]
Categories (3, object): [a < b < c]

See Also
--------
unique
CategoricalIndex.unique
Series.unique