code: def _check_unknown(values, known_values, return_mask=False):
      """
      Helper function to check for unknowns in values to be encoded.
  
      Uses pure python method for object dtype, and numpy method for
      all other dtypes.
  
      Parameters
      ----------
      values : array
          Values to check for unknowns.
      known_values : array
          Known values. Must be unique.
      return_mask : bool, default=False
          If True, return a mask of the same shape as `values` indicating
          the valid values.
  
      Returns
      -------
      diff : list
          The unique values present in `values` and not in `know_values`.
      valid_mask : boolean array
          Additionally returned if ``return_mask=True``.
  
      """
      valid_mask = None
  
      if values.dtype.kind in "OUS":
          values_set = set(values)
          values_set, missing_in_values = _extract_missing(values_set)
  
          uniques_set = set(known_values)
          uniques_set, missing_in_uniques = _extract_missing(
              uniques_set
          )
          diff = values_set - uniques_set
  
          nan_in_diff = (
              missing_in_values.nan and not missing_in_uniques.nan
          )
          none_in_diff = (
              missing_in_values.none and not missing_in_uniques.none
          )
  
          def is_valid(value):
              return (
                  value in uniques_set
                  or missing_in_uniques.none
                  and value is None
                  or missing_in_uniques.nan
                  and is_scalar_nan(value)
              )
  
          if return_mask:
              if diff or nan_in_diff or none_in_diff:
                  valid_mask = np.array(
                      [is_valid(value) for value in values]
                  )
              else:
                  valid_mask = np.ones(len(values), dtype=bool)
  
          diff = list(diff)
          if none_in_diff:
              diff.append(None)
          if nan_in_diff:
              diff.append(np.nan)
      else:
          unique_values = np.unique(values)
          diff = np.setdiff1d(
              unique_values, known_values, assume_unique=True
          )
          if return_mask:
              if diff.size:
                  valid_mask = np.isin(values, known_values)
              else:
                  valid_mask = np.ones(len(values), dtype=bool)
  
          # check for nans in the known_values
          if np.isnan(known_values).any():
              diff_is_nan = np.isnan(diff)
              if diff_is_nan.any():
                  # removes nan from valid_mask
                  if diff.size and return_mask:
                      is_nan = np.isnan(values)
                      valid_mask[is_nan] = 1
  
                  # remove nan from diff
                  diff = diff[~diff_is_nan]
          diff = list(diff)
  
      if return_mask:
          return diff, valid_mask
      return diff
  
imports: from collections import Counter
  from contextlib import suppress
  from typing import NamedTuple
  import numpy
  from .None import is_scalar_nan
label_desc: Use image node_id 7 for calling a global function with example usage: _check_unknown(values, known_values, return_mask) and returns: diff, diff,  valid_mask, unknown