code: def test_dataframe_apply_execution(setup):
      df = pd.DataFrame({"col": [1, 2, 3, 4]})
      mdf = md.DataFrame(df)
  
      apply_func = lambda x: 20 if x[0] else 10
      with pytest.raises(TypeError):
          mdf.apply(apply_func)
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=1
      ).execute()
      assert res.data_type == "series"
      assert "dtype" in res.data_params
      assert not ("dtypes" in res.data_params)
      assert res.data_params["shape"] == (4,)
      pd.testing.assert_series_equal(
          res.fetch(), df.apply(apply_func, axis=1)
      )
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=0
      ).execute()
      assert res.data_type == "series"
      assert "dtype" in res.data_params
      assert not ("dtypes" in res.data_params)
      assert res.data_params["shape"] == (1,)
      pd.testing.assert_series_equal(
          res.fetch(), df.apply(apply_func, axis=0)
      )
  
      apply_func = lambda x: x + 1
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=1
      ).execute()
      assert res.data_type == "dataframe"
      assert "dtypes" in res.data_params
      assert not ("dtype" in res.data_params)
      assert res.data_params["shape"] == (4, 1)
      pd.testing.assert_frame_equal(
          res.fetch(), df.apply(apply_func, axis=1)
      )
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=0
      ).execute()
      assert res.data_type == "dataframe"
      assert "dtypes" in res.data_params
      assert not ("dtype" in res.data_params)
      assert res.data_params["shape"] == (4, 1)
      pd.testing.assert_frame_equal(
          res.fetch(), df.apply(apply_func, axis=0)
      )
  
      apply_func = lambda x: sum(x)
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=1
      ).execute()
      assert res.data_type == "series"
      assert "dtype" in res.data_params
      assert not ("dtypes" in res.data_params)
      assert res.data_params["shape"] == (4,)
      pd.testing.assert_series_equal(
          res.fetch(), df.apply(apply_func, axis=1)
      )
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=0
      ).execute()
      assert res.data_type == "series"
      assert "dtype" in res.data_params
      assert not ("dtypes" in res.data_params)
      assert res.data_params["shape"] == (1,)
      pd.testing.assert_series_equal(
          res.fetch(), df.apply(apply_func, axis=0)
      )
  
      df = pd.DataFrame({"c1": [1, 2, 3, 4], "c2": [5, 6, 7, 8]})
      mdf = md.DataFrame(df)
      apply_func = lambda x: sum(x) / len(x)
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=1
      ).execute()
      assert res.data_type == "series"
      assert "dtype" in res.data_params
      assert res.data_params["dtype"] == "float64"
      assert not ("dtypes" in res.data_params)
      assert res.data_params["shape"] == (4,)
      pd.testing.assert_series_equal(
          res.fetch(), df.apply(apply_func, axis=1)
      )
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=0
      ).execute()
      assert res.data_type == "series"
      assert "dtype" in res.data_params
      assert res.data_params["dtype"] == "float64"
      assert not ("dtypes" in res.data_params)
      assert res.data_params["shape"] == (2,)
      pd.testing.assert_series_equal(
          res.fetch(), df.apply(apply_func, axis=0)
      )
  
      apply_func = lambda x: pd.Series([1, 2])
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=0
      ).execute()
      assert res.data_type == "dataframe"
      assert "dtypes" in res.data_params
      assert res.data_params["shape"] == (2, 2)
      pd.testing.assert_frame_equal(
          res.fetch(), df.apply(apply_func, axis=0)
      )
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=1
      ).execute()
      assert res.data_type == "dataframe"
      assert "dtypes" in res.data_params
      assert res.data_params["shape"] == (4, 2)
      pd.testing.assert_frame_equal(
          res.fetch(), df.apply(apply_func, axis=1)
      )
  
      apply_func = lambda x: [1, 2]
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=0
      ).execute()
      assert res.data_type == "dataframe"
      assert res.data_params["shape"] == (2, 2)
      pd.testing.assert_frame_equal(
          res.fetch(), df.apply(apply_func, axis=0)
      )
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=1
      ).execute()
      assert res.data_type == "series"
      assert res.data_params["shape"] == (4,)
      assert res.data_params["dtype"] == "object"
      pd.testing.assert_series_equal(
          res.fetch(), df.apply(apply_func, axis=1)
      )
  
      apply_func = lambda x: pd.Series(
          [1, 2, 3.0], index=["c1", "c2", "c3"]
      )
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=0
      ).execute()
      assert res.data_type == "dataframe"
      assert res.data_params["shape"] == (3, 2)
      pd.testing.assert_frame_equal(
          res.fetch(), df.apply(apply_func, axis=0)
      )
  
      res = mdf.apply(
          apply_func, output_type="df_or_series", axis=1
      ).execute()
      assert res.data_type == "dataframe"
      assert res.data_params["shape"] == (4, 3)
      pd.testing.assert_frame_equal(
          res.fetch(), df.apply(apply_func, axis=1)
      )
  
      apply_func = lambda x: [1, 2, 3]
      res = mdf.apply(
          apply_func,
          output_type="df_or_series",
          axis=1,
          result_type="expand",
      ).execute()
      expected = df.apply(apply_func, axis=1, result_type="expand")
      pd.testing.assert_frame_equal(res.fetch(), expected)
  
      res = mdf.apply(
          apply_func,
          output_type="df_or_series",
          axis=1,
          result_type="reduce",
      ).execute()
      expected = df.apply(apply_func, axis=1, result_type="reduce")
      pd.testing.assert_series_equal(res.fetch(), expected)
  
      apply_func = lambda x: [1, 2]
      res = mdf.apply(
          apply_func,
          output_type="df_or_series",
          axis=1,
          result_type="broadcast",
      ).execute()
      expected = df.apply(apply_func, axis=1, result_type="broadcast")
      pd.testing.assert_frame_equal(res.fetch(), expected)
  
file_path: mars/mars/dataframe/base/tests/test_apply_execution.py
imports: import numpy
  import pandas
  import pytest
  from ....None import dataframe
  from ....dataframe.core import DataFrame, DATAFRAME_OR_SERIES_TYPE
  from ....dataframe.fetch.core import DataFrameFetch
label_desc: Use image node_id 1 for calling a global function with example usage: test_dataframe_apply_execution(setup) without return types