code: def _encode_pandas_categorical_initial(
      X_col, pd_categories, is_ordered, processing
  ):
      # called under: fit
  
      if processing == "nominal":
          if is_ordered:
              msg = "nominal type invalid for ordered pandas.CategoricalDtype"
              _log.error(msg)
              raise ValueError(msg)
      elif processing == "ordinal":
          if not is_ordered:
              msg = "ordinal type invalid for unordered pandas.CategoricalDtype"
              _log.error(msg)
              raise ValueError(msg)
      elif processing is None or processing == "auto":
          pass
      elif (
          processing == "nominal_prevalence"
          or processing == "nominal_alphabetical"
      ):
          # TODO: we could instead handle this by re-ordering the pandas pd_categories.
          # Someone might want to construct it quickly but then override the pd_categories
          msg = f"{processing} type invalid for pandas.CategoricalDtype"
          _log.error(msg)
          raise ValueError(msg)
      else:
          if isinstance(processing, str):
              # don't allow strings to get to the for loop below
              msg = f"{processing} type invalid for pandas.CategoricalDtype"
              _log.error(msg)
              raise ValueError(msg)
  
          n_items = 0
          n_ordinals = 0
          n_continuous = 0
          try:
              for item in processing:
                  n_items += 1
                  if isinstance(item, str):
                      n_ordinals += 1
                  elif (
                      isinstance(item, float)
                      or isinstance(item, int)
                      or isinstance(item, np.floating)
                      or isinstance(item, np.integer)
                  ):
                      n_continuous += 1
          except TypeError:
              msg = f"{processing} type invalid for pandas.CategoricalDtype"
              _log.error(msg)
              raise ValueError(msg)
  
          if n_continuous == n_items:
              msg = (
                  "continuous type invalid for pandas.CategoricalDtype"
              )
              _log.error(msg)
              raise ValueError(msg)
          elif n_ordinals == n_items:
              if not is_ordered:
                  msg = "ordinal type invalid for unordered pandas.CategoricalDtype"
                  _log.error(msg)
                  raise ValueError(msg)
  
              # TODO: instead of throwing, we could match the ordinal values with the pandas pd_categories and
              # report the rest as bad items.  For now though, just assume it's bad to specify this
              msg = "cannot specify ordinal categories for a pandas.CategoricalDtype which already has categories"
              _log.error(msg)
              raise ValueError(msg)
          else:
              msg = f"{processing} type invalid for pandas.CategoricalDtype"
              _log.error(msg)
              raise ValueError(msg)
  
      categories = dict(zip(pd_categories, count(1)))
      # we'll need int64 for calling C++ anyways
      X_col = X_col.astype(dtype=np.int64, copy=False)
      X_col = X_col + 1
      return X_col, categories
  
imports: from collections import Counter
  from itertools import count
  import numpy
  import numpy.ma
  import logging
label_desc: Use image node_id 4 for calling a global function with example usage: _encode_pandas_categorical_initial(X_col, pd_categories, is_ordered, processing) and returns: X_col,  categories