code: def _encode(values, uniques=None, encode=False, check_unknown=True):
      """Helper function to factorize (find uniques) and encode values.
      Uses pure python method for object dtype, and numpy method for
      all other dtypes.
      The numpy method has the limitation that the `uniques` need to
      be sorted. Importantly, this is not checked but assumed to already be
      the case. The calling method needs to ensure this for all non-object
      values.
      Parameters
      ----------
      values : array
          Values to factorize or encode.
      uniques : array, optional
          If passed, uniques are not determined from passed values (this
          can be because the user specified categories, or because they
          already have been determined in fit).
      encode : bool, default False
          If True, also encode the values into integer codes based on `uniques`.
      check_unknown : bool, default True
          If True, check for values in ``values`` that are not in ``unique``
          and raise an error. This is ignored for object dtype, and treated as
          True in this case. This parameter is useful for
          _BaseEncoder._transform() to avoid calling _encode_check_unknown()
          twice.
      Returns
      -------
      uniques
          If ``encode=False``. The unique values are sorted if the `uniques`
          parameter was None (and thus inferred from the data).
      (uniques, encoded)
          If ``encode=True``.
      """
      if values.dtype == object:
          try:
              res = _encode_python(values, uniques, encode)
          except TypeError:
              raise TypeError("argument must be a string or number")
          return res
      else:
          return _encode_numpy(
              values, uniques, encode, check_unknown=check_unknown
          )
  
imports: import copy
  from numbers import Integral
  import numpy
  from scipy import sparse
  from sklearn.base import BaseEstimator, TransformerMixin
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from autogluon.features.generators import LabelEncoderFeatureGenerator
label_desc: Use image node_id 3 for calling a global function with example usage: _encode(values, uniques, encode, check_unknown) and returns: res, _encode_numpy