code: def _encode(values, *, uniques, check_unknown=True):
      """Helper function to encode values into [0, n_uniques - 1].
  
      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 : tensor
          Values to encode.
      uniques : tensor
          The unique values in `values`. If the dtype is not object, then
          `uniques` needs to be sorted.
      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 _check_unknown()
          twice.
  
      Returns
      -------
      encoded : tensor
          Encoded values
      """
      return _map_to_integer(
          values, uniques, check_unknown=check_unknown
      )
  
file_path: mars/mars/learn/utils/_encode.py
imports: import numpy
  from typing import NamedTuple
  from ...None import tensor, dataframe
  from .core import is_scalar_nan
label_desc: Use image node_id 5 for calling a global function with example usage: _encode(values) and returns: _map_to_integer