class_docstr: Encode values within columns as ordered integer values.
  
  :class:`OrdinalEncoder` encodes categorical features as integers that range from
  :math:`0` to :math:`n - 1`, where :math:`n` is the number of categories.
  
  If you transform a value that isn't in the fitted datset, then the value is encoded
  as ``float("nan")``.
  
  Columns must contain either hashable values or lists of hashable values. Also, you
  can't have both scalars and lists in the same column.
  
  Examples:
      Use :class:`OrdinalEncoder` to encode categorical features as integers.
  
      >>> import pandas as pd
      >>> import ray
      >>> from ray.data.preprocessors import OrdinalEncoder
      >>> df = pd.DataFrame({
      ...     "sex": ["male", "female", "male", "female"],
      ...     "level": ["L4", "L5", "L3", "L4"],
      ... })
      >>> ds = ray.data.from_pandas(df)  # doctest: +SKIP
      >>> encoder = OrdinalEncoder(columns=["sex", "level"])
      >>> encoder.fit_transform(ds).to_pandas()  # doctest: +SKIP
         sex  level
      0    1      1
      1    0      2
      2    1      0
      3    0      1
  
      If you transform a value not present in the original dataset, then the value
      is encoded as ``float("nan")``.
  
      >>> df = pd.DataFrame({"sex": ["female"], "level": ["L6"]})
      >>> ds = ray.data.from_pandas(df)  # doctest: +SKIP
      >>> encoder.transform(ds).to_pandas()  # doctest: +SKIP
         sex  level
      0    0    NaN
  
      :class:`OrdinalEncoder` can also encode categories in a list.
  
      >>> df = pd.DataFrame({
      ...     "name": ["Shaolin Soccer", "Moana", "The Smartest Guys in the Room"],
      ...     "genre": [
      ...         ["comedy", "action", "sports"],
      ...         ["animation", "comedy",  "action"],
      ...         ["documentary"],
      ...     ],
      ... })
      >>> ds = ray.data.from_pandas(df)  # doctest: +SKIP
      >>> encoder = OrdinalEncoder(columns=["genre"])
      >>> encoder.fit_transform(ds).to_pandas()  # doctest: +SKIP
                                  name      genre
      0                 Shaolin Soccer  [2, 0, 4]
      1                          Moana  [1, 2, 0]
      2  The Smartest Guys in the Room        [3]
  
  Args:
      columns: The columns to separately encode.
      encode_lists: If ``True``, encode list elements.  If ``False``, encode
          whole lists (i.e., replace each list with an integer). ``True``
          by default.
  
  .. seealso::
  
      :class:`OneHotEncoder`
          Another preprocessor that encodes categorical data.
class_docstr_tok: ["Encode","values","within","columns","as","ordered","integer","values",".",":","class",":","`","OrdinalEncoder","`","encodes","categorical","features","as","integers","that","range","from",":","math",":","`","0","`","to",":","math",":","`","n","-","1","`",",","where",":","math",":","`","n","`","is","the","number","of","categories",".","If","you","transform","a","value","that","is","n't","in","the","fitted","datset",",","then","the","value","is","encoded","as","``","float","(","``","nan","''",")","``",".","Columns","must","contain","either","hashable","values","or","lists","of","hashable","values",".","Also",",","you","ca","n't","have","both","scalars","and","lists","in","the","same","column",".","Examples",":","Use",":","class",":","`","OrdinalEncoder","`","to","encode","categorical","features","as","integers",".",">",">",">","import","pandas","as","pd",">",">",">","import","ray",">",">",">","from","ray.data.preprocessors","import","OrdinalEncoder",">",">",">","df","=","pd.DataFrame","(","{","...","``","sex","''",":","[","``","male","''",",","``","female","''",",","``","male","''",",","``","female","''","]",",","...","``","level","''",":","[","``","L4","''",",","``","L5","''",",","``","L3","''",",","``","L4","''","]",",","...","}",")",">",">",">","ds","=","ray.data.from_pandas","(","df",")","#","doctest",":","+SKIP",">",">",">","encoder","=","OrdinalEncoder","(","columns=","[","``","sex","''",",","``","level","''","]",")",">",">",">","encoder.fit_transform","(","ds",")",".to_pandas","(",")","#","doctest",":","+SKIP","sex","level","0","1","1","1","0","2","2","1","0","3","0","1","If","you","transform","a","value","not","present","in","the","original","dataset",",","then","the","value","is","encoded","as","``","float","(","``","nan","''",")","``",".",">",">",">","df","=","pd.DataFrame","(","{","``","sex","''",":","[","``","female","''","]",",","``","level","''",":","[","``","L6","''","]","}",")",">",">",">","ds","=","ray.data.from_pandas","(","df",")","#","doctest",":","+SKIP",">",">",">","encoder.transform","(","ds",")",".to_pandas","(",")","#","doctest",":","+SKIP","sex","level","0","0","NaN",":","class",":","`","OrdinalEncoder","`","can","also","encode","categories","in","a","list",".",">",">",">","df","=","pd.DataFrame","(","{","...","``","name","''",":","[","``","Shaolin","Soccer","''",",","``","Moana","''",",","``","The","Smartest","Guys","in","the","Room","''","]",",","...","``","genre","''",":","[","...","[","``","comedy","''",",","``","action","''",",","``","sports","''","]",",","...","[","``","animation","''",",","``","comedy","''",",","``","action","''","]",",","...","[","``","documentary","''","]",",","...","]",",","...","}",")",">",">",">","ds","=","ray.data.from_pandas","(","df",")","#","doctest",":","+SKIP",">",">",">","encoder","=","OrdinalEncoder","(","columns=","[","``","genre","''","]",")",">",">",">","encoder.fit_transform","(","ds",")",".to_pandas","(",")","#","doctest",":","+SKIP","name","genre","0","Shaolin","Soccer","[","2",",","0",",","4","]","1","Moana","[","1",",","2",",","0","]","2","The","Smartest","Guys","in","the","Room","[","3","]","Args",":","columns",":","The","columns","to","separately","encode",".","encode_lists",":","If","``","True","``",",","encode","list","elements",".","If","``","False","``",",","encode","whole","lists","(","i.e.",",","replace","each","list","with","an","integer",")",".","``","True","``","by","default",".","..","seealso",":",":",":","class",":","`","OneHotEncoder","`","Another","preprocessor","that","encodes","categorical","data","."]
code: def _fit(self, dataset: Dataset) -> Preprocessor:
      self.stats_ = _get_unique_value_indices(
          dataset, self.columns, encode_lists=self.encode_lists
      )
      return self
  
imports: from collections import Counter, OrderedDict
  from functools import partial
  from typing import Dict, List, Optional
  import numpy
  import pandas
  import pandas.api.types
  from ray.air.util.data_batch_conversion import BatchFormat
  from ray.data import Dataset
  from ray.data.preprocessor import Preprocessor, PreprocessorNotFittedException
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 2 for calling the OrdinalEncoder obj's underlying member method code with example usage: obj._fit(dataset) and returns: self