code: def test_categorizer(predefined_dtypes):
      """Tests basic Categorizer functionality."""
      col_a = ["red", "green", "blue", "red", "red"]
      col_b = ["warm", "cold", "hot", "cold", None]
      col_c = [1, 10, 5, 10, 1]
      in_df = pd.DataFrame.from_dict(
          {"A": col_a, "B": col_b, "C": col_c}
      )
      ds = ray.data.from_pandas(in_df)
  
      columns = ["B", "C"]
      if predefined_dtypes:
          expected_dtypes = {
              "B": pd.CategoricalDtype(
                  ["cold", "hot", "warm"], ordered=True
              ),
              "C": pd.CategoricalDtype([1, 5, 10]),
          }
          dtypes = {
              "B": pd.CategoricalDtype(
                  ["cold", "hot", "warm"], ordered=True
              )
          }
      else:
          expected_dtypes = {
              "B": pd.CategoricalDtype(["cold", "hot", "warm"]),
              "C": pd.CategoricalDtype([1, 5, 10]),
          }
          columns = ["B", "C"]
          dtypes = None
  
      encoder = Categorizer(columns, dtypes)
  
      # Transform with unfitted preprocessor.
      with pytest.raises(PreprocessorNotFittedException):
          encoder.transform(ds)
  
      # Fit data.
      encoder.fit(ds)
      assert encoder.stats_ == expected_dtypes
  
      # Transform data.
      transformed = encoder.transform(ds)
      out_df = transformed.to_pandas()
  
      assert out_df.dtypes["A"] == np.object_
      assert out_df.dtypes["B"] == expected_dtypes["B"]
      assert out_df.dtypes["C"] == expected_dtypes["C"]
  
      # Transform batch.
      pred_col_a = ["blue", "yellow", None]
      pred_col_b = ["cold", "warm", "other"]
      pred_col_c = [10, 1, 20]
      pred_in_df = pd.DataFrame.from_dict(
          {"A": pred_col_a, "B": pred_col_b, "C": pred_col_c}
      )
  
      pred_out_df = encoder.transform_batch(pred_in_df)
  
      assert pred_out_df.dtypes["A"] == np.object_
      assert pred_out_df.dtypes["B"] == expected_dtypes["B"]
      assert pred_out_df.dtypes["C"] == expected_dtypes["C"]
  
file_path: ray/python/ray/data/tests/preprocessors/test_encoder.py
imports: import numpy
  import pandas
  import pytest
  import ray
  from ray.data.preprocessor import PreprocessorNotFittedException
  from ray.data.preprocessors import Categorizer, LabelEncoder, MultiHotEncoder, OneHotEncoder, OrdinalEncoder
label_desc: Use image node_id 8 for calling a global function with example usage: test_categorizer(predefined_dtypes) without return types