code: def _encode_categorical(
      values: pd.Series,
      uniques: Optional[np.ndarray] = None,
      encode: bool = False,
  ):
      new_uniques = np.asarray(values.cat.categories)
  
      if uniques is not None:
          diff = list(
              np.setdiff1d(uniques, new_uniques, assume_unique=True)
          )
          if diff:
              raise ValueError(
                  "y contains previously unseen labels: {}".format(diff)
              )
  
      uniques = new_uniques
  
      if encode:
          return uniques, values.cat.codes
      else:
          return uniques
  
imports: from __future__ import division
  from operator import getitem
  from typing import Optional, Union
  import dask.array
  import dask.dataframe
  import numpy
  import pandas
  import scipy.sparse
  import sklearn.preprocessing
  from sklearn.utils.validation import check_is_fitted
  from .._typing import ArrayLike, SeriesType
label_desc: Use image node_id 1 for calling a global function with example usage: _encode_categorical(values, uniques, encode) and returns: uniques,  values, uniques