code: def test_groupby_getitem(setup):
      rs = np.random.RandomState(0)
      data_size = 100
      raw = pd.DataFrame(
          {
              "a": rs.randint(0, 10, size=(data_size,)),
              "b": rs.randint(0, 10, size=(data_size,)),
              "c": rs.choice(list("abcd"), size=(data_size,)),
          },
          index=pd.MultiIndex.from_tuples(
              [(i % 3, "i" + str(i)) for i in range(data_size)]
          ),
      )
      mdf = md.DataFrame(raw, chunk_size=13)
  
      r = mdf.groupby(level=0)[["a", "b"]]
      assert_groupby_equal(
          r.execute().fetch(),
          raw.groupby(level=0)[["a", "b"]],
          with_selection=True,
      )
  
      for method in ("tree", "shuffle"):
          r = mdf.groupby(level=0)[["a", "b"]].sum(method=method)
          pd.testing.assert_frame_equal(
              r.execute().fetch().sort_index(),
              raw.groupby(level=0)[["a", "b"]].sum().sort_index(),
          )
  
      r = mdf.groupby(level=0)[["a", "b"]].apply(lambda x: x + 1)
      pd.testing.assert_frame_equal(
          r.execute().fetch().sort_index(),
          raw.groupby(level=0)[["a", "b"]]
          .apply(lambda x: x + 1)
          .sort_index(),
      )
  
      r = mdf.groupby("b")[["a", "b"]]
      assert_groupby_equal(
          r.execute().fetch(),
          raw.groupby("b")[["a", "b"]],
          with_selection=True,
      )
  
      r = mdf.groupby("b")[["a", "c"]]
      assert_groupby_equal(
          r.execute().fetch(),
          raw.groupby("b")[["a", "c"]],
          with_selection=True,
      )
  
      for method in ("tree", "shuffle"):
          r = mdf.groupby("b")[["a", "b"]].sum(method=method)
          pd.testing.assert_frame_equal(
              r.execute().fetch().sort_index(),
              raw.groupby("b")[["a", "b"]].sum().sort_index(),
          )
  
          r = mdf.groupby("b")[["a", "b"]].agg(
              ["sum", "count"], method=method
          )
          pd.testing.assert_frame_equal(
              r.execute().fetch().sort_index(),
              raw.groupby("b")[["a", "b"]]
              .agg(["sum", "count"])
              .sort_index(),
          )
  
          r = mdf.groupby("b")[["a", "c"]].agg(
              ["sum", "count"], method=method
          )
          pd.testing.assert_frame_equal(
              r.execute().fetch().sort_index(),
              raw.groupby("b")[["a", "c"]]
              .agg(["sum", "count"])
              .sort_index(),
          )
  
      r = mdf.groupby("b")[["a", "b"]].apply(lambda x: x + 1)
      pd.testing.assert_frame_equal(
          r.execute().fetch().sort_index(),
          raw.groupby("b")[["a", "b"]]
          .apply(lambda x: x + 1)
          .sort_index(),
      )
  
      r = mdf.groupby("b")[["a", "b"]].transform(lambda x: x + 1)
      pd.testing.assert_frame_equal(
          r.execute().fetch().sort_index(),
          raw.groupby("b")[["a", "b"]]
          .transform(lambda x: x + 1)
          .sort_index(),
      )
  
      r = mdf.groupby("b")[["a", "b"]].cumsum()
      pd.testing.assert_frame_equal(
          r.execute().fetch().sort_index(),
          raw.groupby("b")[["a", "b"]].cumsum().sort_index(),
      )
  
      r = mdf.groupby("b").a
      assert_groupby_equal(
          r.execute().fetch(), raw.groupby("b").a, with_selection=True
      )
  
      for method in ("shuffle", "tree"):
          r = mdf.groupby("b").a.sum(method=method)
          pd.testing.assert_series_equal(
              r.execute().fetch().sort_index(),
              raw.groupby("b").a.sum().sort_index(),
          )
  
          r = mdf.groupby("b").a.agg(
              ["sum", "mean", "var"], method=method
          )
          pd.testing.assert_frame_equal(
              r.execute().fetch().sort_index(),
              raw.groupby("b")
              .a.agg(["sum", "mean", "var"])
              .sort_index(),
          )
  
          r = mdf.groupby("b", as_index=False).a.sum(method=method)
          pd.testing.assert_frame_equal(
              r.execute().fetch().sort_values("b", ignore_index=True),
              raw.groupby("b", as_index=False)
              .a.sum()
              .sort_values("b", ignore_index=True),
          )
  
          r = mdf.groupby("b", as_index=False).b.count(method=method)
          result = (
              r.execute().fetch().sort_values("b", ignore_index=True)
          )
          try:
              expected = (
                  raw.groupby("b", as_index=False)
                  .b.count()
                  .sort_values("b", ignore_index=True)
              )
          except ValueError:
              expected = raw.groupby("b").b.count().to_frame()
              expected.index.names = [None] * expected.index.nlevels
              expected = expected.sort_values("b", ignore_index=True)
          pd.testing.assert_frame_equal(result, expected)
  
          r = mdf.groupby("b", as_index=False).b.agg(
              {"cnt": "count"}, method=method
          )
          result = (
              r.execute().fetch().sort_values("b", ignore_index=True)
          )
          try:
              expected = (
                  raw.groupby("b", as_index=False)
                  .b.agg({"cnt": "count"})
                  .sort_values("b", ignore_index=True)
              )
          except ValueError:
              expected = (
                  raw.groupby("b").b.agg({"cnt": "count"}).to_frame()
              )
              expected.index.names = [None] * expected.index.nlevels
              expected = expected.sort_values("b", ignore_index=True)
          pd.testing.assert_frame_equal(result, expected)
  
      r = mdf.groupby("b").a.apply(lambda x: x + 1)
      pd.testing.assert_series_equal(
          r.execute().fetch().sort_index(),
          raw.groupby("b").a.apply(lambda x: x + 1).sort_index(),
      )
  
      r = mdf.groupby("b").a.transform(lambda x: x + 1)
      pd.testing.assert_series_equal(
          r.execute().fetch().sort_index(),
          raw.groupby("b").a.transform(lambda x: x + 1).sort_index(),
      )
  
      r = mdf.groupby("b").a.cumsum()
      pd.testing.assert_series_equal(
          r.execute().fetch().sort_index(),
          raw.groupby("b").a.cumsum().sort_index(),
      )
  
      # special test for selection key == 0
      raw = pd.DataFrame(rs.rand(data_size, 10))
      raw[0] = 0
      mdf = md.DataFrame(raw, chunk_size=13)
      r = mdf.groupby(0, as_index=False)[0].agg(
          {"cnt": "count"}, method="tree"
      )
      pd.testing.assert_frame_equal(
          r.execute().fetch().sort_index(),
          raw.groupby(0, as_index=False)[0].agg({"cnt": "count"}),
      )
  
      # test groupby getitem then agg(#GH 2640)
      rs = np.random.RandomState(0)
      raw = pd.DataFrame(
          {
              "c1": rs.randint(0, 10, size=(100,)).astype(np.int64),
              "c2": rs.choice(["a", "b", "c"], (100,)),
              "c3": rs.rand(100),
              "c4": rs.rand(100),
          }
      )
      mdf = md.DataFrame(raw, chunk_size=20)
  
      r = mdf.groupby(["c2"])[["c1", "c3"]].agg(
          {"c1": "max", "c3": "min"}, method="tree"
      )
      pd.testing.assert_frame_equal(
          r.execute().fetch(),
          raw.groupby(["c2"])[["c1", "c3"]].agg(
              {"c1": "max", "c3": "min"}
          ),
      )
  
      mdf = md.DataFrame(raw.copy(), chunk_size=30)
      r = mdf.groupby(["c2"])[["c1", "c4"]].agg(
          {"c1": "max", "c4": "mean"}, method="shuffle"
      )
      pd.testing.assert_frame_equal(
          r.execute().fetch().sort_index(),
          raw.groupby(["c2"])[["c1", "c4"]].agg(
              {"c1": "max", "c4": "mean"}
          ),
      )
  
      # test anonymous function lists
      agg_funs = [lambda x: (x + 1).sum()]
      r = mdf.groupby(["c2"])["c1"].agg(agg_funs)
      pd.testing.assert_frame_equal(
          r.execute().fetch(), raw.groupby(["c2"])["c1"].agg(agg_funs)
      )
  
      # test group by multiple cols
      r = mdf.groupby(["c1", "c2"], as_index=False)["c3"].sum()
      expected = raw.groupby(["c1", "c2"], as_index=False)["c3"].sum()
      pd.testing.assert_frame_equal(
          r.execute()
          .fetch()
          .sort_values(["c1", "c2"])
          .reset_index(drop=True),
          expected.sort_values(["c1", "c2"]).reset_index(drop=True),
      )
  
      r = mdf.groupby(["c1", "c2"], as_index=False)["c3"].agg(["sum"])
      expected = raw.groupby(["c1", "c2"], as_index=False)["c3"].agg(
          ["sum"]
      )
      pd.testing.assert_frame_equal(
          r.execute().fetch().sort_values(["c1", "c2"]),
          expected.sort_values(["c1", "c2"]),
      )
  
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 2 for calling a global function with example usage: test_groupby_getitem(setup) without return types