nodes: 0, module; 1, function_definition; 2, function_name:unique; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, comment:# unlike np.unique, unique1d does not sort; 8, expression_statement; 9, expression_statement; 10, comment:# keep nan in codes; 11, expression_statement; 12, comment:# exclude nan from indexer for categories; 13, expression_statement; 14, if_statement; 15, return_statement; 16, comment:"""
          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
  
          """; 17, assignment; 18, assignment; 19, assignment; 20, assignment; 21, attribute; 22, block; 23, call; 24, identifier:unique_codes; 25, call; 26, identifier:cat; 27, call; 28, attribute; 29, identifier:unique_codes; 30, identifier:take_codes; 31, subscript; 32, identifier:self; 33, identifier:ordered; 34, expression_statement; 35, attribute; 36, argument_list; 37, identifier:unique1d; 38, argument_list; 39, attribute; 40, argument_list; 41, identifier:cat; 42, identifier:_codes; 43, identifier:unique_codes; 44, comparison_operator:unique_codes != -1; 45, assignment; 46, identifier:cat; 47, identifier:set_categories; 48, call; 49, attribute; 50, identifier:self; 51, identifier:copy; 52, identifier:unique_codes; 53, unary_operator; 54, identifier:take_codes; 55, call; 56, attribute; 57, argument_list; 58, identifier:self; 59, identifier:codes; 60, integer:1; 61, attribute; 62, argument_list; 63, attribute; 64, identifier:take; 65, identifier:take_codes; 66, identifier:np; 67, identifier:sort; 68, identifier:take_codes; 69, identifier:cat; 70, identifier:categories
code: def unique(self):
          """
          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
  
          """
  
          # unlike np.unique, unique1d does not sort
          unique_codes = unique1d(self.codes)
          cat = self.copy()
  
          # keep nan in codes
          cat._codes = unique_codes
  
          # exclude nan from indexer for categories
          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))