code: def test_series_apply():
      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)
  
      r = tile(series.apply("add", args=(1,)))
      assert r.op._op_type_ == opcodes.ADD
  
      r = tile(series.apply(np.sqrt))
      assert np.dtype("float64") == r.dtype
      assert r.shape == series.shape
      assert r.index_value is series.index_value
      assert r.op._op_type_ == opcodes.APPLY
      assert r.op.output_types[0] == OutputType.series
      assert r.chunks[0].shape == (5,)
      assert r.chunks[0].inputs[0].shape == (5,)
  
      r = tile(series.apply("sqrt"))
      assert np.dtype("float64") == r.dtype
      assert r.shape == series.shape
      assert r.op._op_type_ == opcodes.APPLY
      assert r.op.output_types[0] == OutputType.series
      assert r.chunks[0].shape == (5,)
      assert r.chunks[0].inputs[0].shape == (5,)
  
      r = tile(series.apply(lambda x: [x, x + 1], convert_dtype=False))
      assert np.dtype("object") == r.dtype
      assert r.shape == series.shape
      assert r.op._op_type_ == opcodes.APPLY
      assert r.op.output_types[0] == OutputType.series
      assert r.chunks[0].shape == (5,)
      assert r.chunks[0].inputs[0].shape == (5,)
  
      s_raw2 = pd.Series([np.array([1, 2, 3]), np.array([4, 5, 6])])
      series = from_pandas_series(s_raw2)
  
      r = series.apply(np.sum)
      assert r.dtype == np.dtype(object)
  
      r = series.apply(
          lambda x: pd.Series([1]), output_type="dataframe"
      )
      expected = s_raw2.apply(lambda x: pd.Series([1]))
      pd.testing.assert_series_equal(r.dtypes, expected.dtypes)
  
      dtypes = pd.Series([np.dtype(float)] * 3)
      r = series.apply(
          pd.Series, output_type="dataframe", dtypes=dtypes
      )
      assert r.ndim == 2
      pd.testing.assert_series_equal(r.dtypes, dtypes)
      assert r.shape == (2, 3)
  
      def apply_with_error(_):
          raise ValueError
  
      r = series.apply(
          apply_with_error, output_type="dataframe", dtypes=dtypes
      )
      assert r.ndim == 2
  
      r = series.apply(
          pd.Series,
          output_type="dataframe",
          dtypes=dtypes,
          index=pd.RangeIndex(2),
      )
      assert r.ndim == 2
      pd.testing.assert_series_equal(r.dtypes, dtypes)
      assert r.shape == (2, 3)
  
      with pytest.raises(AttributeError, match="abc"):
          series.apply("abc")
  
      with pytest.raises(TypeError):
          # dtypes not provided
          series.apply(lambda x: x.tolist(), output_type="dataframe")
  
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 6 for calling a global function with example usage: test_series_apply() without return types