code: def test_nested_chain():
      """Tests Chain-inside-Chain functionality."""
      col_a = [-1, -1, 1, 1]
      col_b = [1, 1, 1, None]
      col_c = ["sunday", "monday", "tuesday", "tuesday"]
      in_df = pd.DataFrame.from_dict(
          {"A": col_a, "B": col_b, "C": col_c}
      )
      ds = ray.data.from_pandas(in_df)
  
      def udf(df):
          df["A"] *= 2
          return df
  
      batch_mapper = BatchMapper(fn=udf, batch_format="pandas")
      imputer = SimpleImputer(["B"])
      scaler = StandardScaler(["A", "B"])
      encoder = LabelEncoder("C")
      chain = Chain(Chain(scaler, imputer), encoder, batch_mapper)
  
      # Fit data.
      chain.fit(ds)
      assert imputer.stats_ == {
          "mean(B)": 0.0,
      }
      assert scaler.stats_ == {
          "mean(A)": 0.0,
          "mean(B)": 1.0,
          "std(A)": 1.0,
          "std(B)": 0.0,
      }
      assert encoder.stats_ == {
          "unique_values(C)": {"monday": 0, "sunday": 1, "tuesday": 2}
      }
  
      # Transform data.
      transformed = chain.transform(ds)
      out_df = transformed.to_pandas()
  
      processed_col_a = [-2.0, -2.0, 2.0, 2.0]
      processed_col_b = [0.0, 0.0, 0.0, 0.0]
      processed_col_c = [1, 0, 2, 2]
      expected_df = pd.DataFrame.from_dict(
          {
              "A": processed_col_a,
              "B": processed_col_b,
              "C": processed_col_c,
          }
      )
  
      assert out_df.equals(expected_df)
  
      # Transform batch.
      pred_col_a = [1, 2, None]
      pred_col_b = [0, None, 2]
      pred_col_c = ["monday", "tuesday", "wednesday"]
      pred_in_df = pd.DataFrame.from_dict(
          {"A": pred_col_a, "B": pred_col_b, "C": pred_col_c}
      )
  
      pred_out_df = chain.transform_batch(pred_in_df)
  
      pred_processed_col_a = [2, 4, None]
      pred_processed_col_b = [-1.0, 0.0, 1.0]
      pred_processed_col_c = [0, 2, None]
      pred_expected_df = pd.DataFrame.from_dict(
          {
              "A": pred_processed_col_a,
              "B": pred_processed_col_b,
              "C": pred_processed_col_c,
          }
      )
  
      assert pred_out_df.equals(pred_expected_df)
  
file_path: ray/python/ray/data/tests/preprocessors/test_chain.py
imports: import pandas
  import pytest
  import ray
  from ray.air.util.data_batch_conversion import BatchFormat
  from ray.data.preprocessor import Preprocessor
  from ray.data.preprocessors import BatchMapper, Chain, LabelEncoder, SimpleImputer, StandardScaler
label_desc: Use image node_id 3 for calling a global function with example usage: test_nested_chain() and returns: df