def unique(self):
    "\n        Return the ``Categorical`` which ``categories`` and ``codes`` are\n        unique. Unused categories are NOT returned.\n\n        - unordered category: values and categories are sorted by appearance\n          order.\n        - ordered category: values are sorted by appearance order, categories\n          keeps existing order.\n\n        Returns\n        -------\n        unique values : ``Categorical``\n\n        Examples\n        --------\n        An unordered Categorical will return categories in the\n        order of appearance.\n\n        >>> pd.Categorical(list('baabc'))\n        [b, a, c]\n        Categories (3, object): [b, a, c]\n\n        >>> pd.Categorical(list('baabc'), categories=list('abc'))\n        [b, a, c]\n        Categories (3, object): [b, a, c]\n\n        An ordered Categorical preserves the category ordering.\n\n        >>> pd.Categorical(list('baabc'),\n        ...                categories=list('abc'),\n        ...                ordered=True)\n        [b, a, c]\n        Categories (3, object): [a < b < c]\n\n        See Also\n        --------\n        unique\n        CategoricalIndex.unique\n        Series.unique\n\n        "
    unique_codes = unique1d(self.codes)
    cat = self.copy()
    cat._codes = unique_codes
    take_codes = unique_codes[(unique_codes != (- 1))]
    if self.ordered:
        take_codes = np.sort(take_codes)
    return cat.set_categories(cat.categories.take(take_codes))
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
def unique(self):
    "\n        Return the ``Categorical`` which ``categories`` and ``codes`` are\n        unique. Unused categories are NOT returned.\n\n        - unordered category: values and categories are sorted by appearance\n          order.\n        - ordered category: values are sorted by appearance order, categories\n          keeps existing order.\n\n        Returns\n        -------\n        unique values : ``Categorical``\n\n        Examples\n        --------\n        An unordered Categorical will return categories in the\n        order of appearance.\n\n        >>> pd.Categorical(list('baabc'))\n        [b, a, c]\n        Categories (3, object): [b, a, c]\n\n        >>> pd.Categorical(list('baabc'), categories=list('abc'))\n        [b, a, c]\n        Categories (3, object): [b, a, c]\n\n        An ordered Categorical preserves the category ordering.\n\n        >>> pd.Categorical(list('baabc'),\n        ...                categories=list('abc'),\n        ...                ordered=True)\n        [b, a, c]\n        Categories (3, object): [a < b < c]\n\n        See Also\n        --------\n        unique\n        CategoricalIndex.unique\n        Series.unique\n\n        "
    unique_codes = unique1d(self.codes)
    cat = self.copy()
    cat._codes = unique_codes
    take_codes = unique_codes[(unique_codes != (- 1))]
    if self.ordered:
        take_codes = np.sort(take_codes)
    return cat.set_categories(cat.categories.take(take_codes))