nodes: 0, module; 1, function_definition; 2, function_name:unique_value_groups; 3, parameters; 4, block; 5, identifier:ar; 6, default_parameter; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, for_statement; 11, return_statement; 12, identifier:sort; 13, True; 14, comment:"""Group an array by its unique values.
  
      Parameters
      ----------
      ar : array-like
          Input array. This will be flattened if it is not already 1-D.
      sort : boolean, optional
          Whether or not to sort unique values.
  
      Returns
      -------
      values : np.ndarray
          Sorted, unique values as returned by `np.unique`.
      indices : list of lists of int
          Each element provides the integer indices in `ar` with values given by
          the corresponding value in `unique_values`.
      """; 15, assignment; 16, assignment; 17, pattern_list; 18, call; 19, block; 20, expression_list; 21, pattern_list; 22, call; 23, identifier:groups; 24, list_comprehension; 25, identifier:n; 26, identifier:g; 27, identifier:enumerate; 28, argument_list; 29, if_statement; 30, identifier:values; 31, identifier:groups; 32, identifier:inverse; 33, identifier:values; 34, attribute; 35, argument_list; 36, list; 37, for_in_clause; 38, identifier:inverse; 39, comparison_operator:g >= 0; 40, comment:# pandas uses -1 to mark NaN, but doesn't include them in values; 41, block; 42, identifier:pd; 43, identifier:factorize; 44, identifier:ar; 45, keyword_argument; 46, identifier:_; 47, call; 48, identifier:g; 49, integer:0; 50, expression_statement; 51, identifier:sort; 52, identifier:sort; 53, identifier:range; 54, argument_list; 55, call; 56, call; 57, attribute; 58, argument_list; 59, identifier:len; 60, argument_list; 61, subscript; 62, identifier:append; 63, identifier:n; 64, identifier:values; 65, identifier:groups; 66, identifier:g
code: def unique_value_groups(ar, sort=True):
      """Group an array by its unique values.
  
      Parameters
      ----------
      ar : array-like
          Input array. This will be flattened if it is not already 1-D.
      sort : boolean, optional
          Whether or not to sort unique values.
  
      Returns
      -------
      values : np.ndarray
          Sorted, unique values as returned by `np.unique`.
      indices : list of lists of int
          Each element provides the integer indices in `ar` with values given by
          the corresponding value in `unique_values`.
      """
      inverse, values = pd.factorize(ar, sort=sort)
      groups = [[] for _ in range(len(values))]
      for n, g in enumerate(inverse):
          if g >= 0:
              # pandas uses -1 to mark NaN, but doesn't include them in values
              groups[g].append(n)
      return values, groups