code: def test_groupby_apply_closure(setup):
      # DataFrame
      df1 = pd.DataFrame(
          {
              "a": [3, 4, 5, 3, 5, 4, 1, 2, 3],
              "b": [1, 3, 4, 5, 6, 5, 4, 4, 4],
              "c": list("aabaaddce"),
          }
      )
  
      x, y = 10, 11
  
      def apply_closure_df(df):
          return df["a"].max() * x
  
      def apply_closure_series(s):
          return s.mean() * y
  
      class callable_df:
          def __init__(self):
              self.x = 10
  
          def __call__(self, df):
              return df["a"].max() * x
  
      class callable_series:
          def __init__(self):
              self.y = 11
  
          def __call__(self, s):
              return s.mean() * y
  
      mdf = md.DataFrame(df1, chunk_size=3)
  
      applied = mdf.groupby("b").apply(apply_closure_df)
      pd.testing.assert_series_equal(
          applied.execute().fetch().sort_index(),
          df1.groupby("b").apply(apply_closure_df).sort_index(),
      )
  
      cdf = callable_df()
      applied = mdf.groupby("b").apply(cdf)
      pd.testing.assert_series_equal(
          applied.execute().fetch().sort_index(),
          df1.groupby("b").apply(cdf).sort_index(),
      )
  
      # Series
      series1 = pd.Series([3, 4, 5, 3, 5, 4, 1, 2, 3])
      ms1 = md.Series(series1, chunk_size=3)
  
      applied = ms1.groupby(lambda x: x % 3).apply(apply_closure_series)
      pd.testing.assert_series_equal(
          applied.execute().fetch().sort_index(),
          series1.groupby(lambda x: x % 3)
          .apply(apply_closure_series)
          .sort_index(),
      )
  
      cs = callable_series()
      applied = ms1.groupby(lambda x: x % 3).apply(cs)
      pd.testing.assert_series_equal(
          applied.execute().fetch().sort_index(),
          series1.groupby(lambda x: x % 3).apply(cs).sort_index(),
      )
  
imports: from collections import OrderedDict
  import numpy
  import pandas
  import pytest
  from ....None import dataframe
  from ....config import option_context
  from ....core.operand import OperandStage
  from ....tests.core import assert_groupby_equal, require_cudf
  from ....utils import arrow_array_to_objects, pd_release_version
  from ...core import DATAFRAME_OR_SERIES_TYPE
  from ..aggregation import DataFrameGroupByAgg
label_desc: Use image node_id 12 for calling a global function with example usage: test_groupby_apply_closure(setup) and returns: unknown, unknown, unknown, unknown