code: def test_transform():
      cols = [chr(ord("A") + i) for i in range(10)]
      df_raw = pd.DataFrame(
          dict((c, [i**2 for i in range(20)]) for c in cols)
      )
      df = from_pandas_df(df_raw, chunk_size=5)
  
      idxes = [chr(ord("A") + i) for i in range(20)]
      s_raw = pd.Series([i**2 for i in range(20)], index=idxes)
      series = from_pandas_series(s_raw, chunk_size=5)
  
      def rename_fn(f, new_name):
          f.__name__ = new_name
          return f
  
      old_chunk_store_limit = options.chunk_store_limit
      try:
          options.chunk_store_limit = 20
  
          # DATAFRAME CASES
  
          # test transform with infer failure
          def transform_df_with_err(v):
              assert len(v) > 2
              return v.sort_values()
  
          with pytest.raises(TypeError):
              df.transform(transform_df_with_err)
  
          r = tile(
              df.transform(transform_df_with_err, dtypes=df_raw.dtypes)
          )
          assert r.shape == df.shape
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (df.shape[0], 20 // df.shape[0])
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          # test transform scenarios on data frames
          r = tile(df.transform(lambda x: list(range(len(x)))))
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == df.shape
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (df.shape[0], 20 // df.shape[0])
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          r = tile(df.transform(lambda x: list(range(len(x))), axis=1))
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == df.shape
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (20 // df.shape[1], df.shape[1])
          assert r.chunks[0].inputs[0].shape[1] == df_raw.shape[1]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          r = tile(df.transform(["cumsum", "cummax", lambda x: x + 1]))
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == (df.shape[0], df.shape[1] * 3)
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (
              df.shape[0],
              20 // df.shape[0] * 3,
          )
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          r = tile(
              df.transform(
                  {
                      "A": "cumsum",
                      "D": ["cumsum", "cummax"],
                      "F": lambda x: x + 1,
                  }
              )
          )
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == (df.shape[0], 4)
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (df.shape[0], 1)
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          # test agg scenarios on series
          r = tile(df.transform(lambda x: x.iloc[:-1], _call_agg=True))
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == (np.nan, df.shape[1])
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (np.nan, 1)
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          r = tile(
              df.transform(
                  lambda x: x.iloc[:-1], axis=1, _call_agg=True
              )
          )
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == (df.shape[0], np.nan)
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (2, np.nan)
          assert r.chunks[0].inputs[0].shape[1] == df_raw.shape[1]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          fn_list = [
              rename_fn(
                  lambda x: x.iloc[1:].reset_index(drop=True), "f1"
              ),
              lambda x: x.iloc[:-1].reset_index(drop=True),
          ]
          r = tile(df.transform(fn_list, _call_agg=True))
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == (np.nan, df.shape[1] * 2)
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (np.nan, 2)
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          r = tile(df.transform(lambda x: x.sum(), _call_agg=True))
          assert r.dtype == np.dtype("int64")
          assert r.shape == (df.shape[1],)
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.series
          assert r.chunks[0].shape == (20 // df.shape[0],)
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          fn_dict = {
              "A": rename_fn(
                  lambda x: x.iloc[1:].reset_index(drop=True), "f1"
              ),
              "D": [
                  rename_fn(
                      lambda x: x.iloc[1:].reset_index(drop=True), "f1"
                  ),
                  lambda x: x.iloc[:-1].reset_index(drop=True),
              ],
              "F": lambda x: x.iloc[:-1].reset_index(drop=True),
          }
          r = tile(df.transform(fn_dict, _call_agg=True))
          assert all(v == np.dtype("int64") for v in r.dtypes) is True
          assert r.shape == (np.nan, 4)
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.dataframe
          assert r.chunks[0].shape == (np.nan, 1)
          assert r.chunks[0].inputs[0].shape[0] == df_raw.shape[0]
          assert (
              r.chunks[0].inputs[0].op._op_type_ == opcodes.CONCATENATE
          )
  
          # SERIES CASES
          # test transform scenarios on series
          r = tile(series.transform(lambda x: x + 1))
          assert np.dtype("int64") == r.dtype
          assert r.shape == series.shape
          assert r.op._op_type_ == opcodes.TRANSFORM
          assert r.op.output_types[0] == OutputType.series
          assert r.chunks[0].shape == (5,)
          assert r.chunks[0].inputs[0].shape == (5,)
      finally:
          options.chunk_store_limit = old_chunk_store_limit
  
imports: from typing import List, Union
  import numpy
  import pandas
  import pytest
  from ....None import opcodes
  from ....config import options, option_context
  from ....core import OutputType, tile, Tileable
  from ....core.graph import TileableGraph, TileableGraphBuilder, TileContext, ChunkGraphBuilder
  from ....core.operand import OperandStage
  from ....tensor.core import TENSOR_TYPE
  from ...None import eval, cut, get_dummies, to_numeric
  from ...core import DATAFRAME_TYPE, SERIES_TYPE, SERIES_CHUNK_TYPE, INDEX_TYPE, CATEGORICAL_TYPE, CATEGORICAL_CHUNK_TYPE, DataFrameData, SeriesData
  from ...datasource.dataframe import from_pandas
  from ...datasource.series import from_pandas
  from ...datasource.index import from_pandas
  from ..None import to_gpu, to_cpu, astype
label_desc: Use image node_id 7 for calling a global function with example usage: test_transform() and returns: f, v