code: def test_aggregate(self):
      pdf = pd.DataFrame(
          {
              "A": [1, 1, 2, 2],
              "B": [1, 2, 3, 4],
              "C": [0.362, 0.227, 1.267, -0.562],
          }
      )
      psdf = ps.from_pandas(pdf)
  
      for as_index in [True, False]:
          if as_index:
  
              def sort(df):
                  return df.sort_index()
  
          else:
  
              def sort(df):
                  return df.sort_values(list(df.columns)).reset_index(
                      drop=True
                  )
  
          for kkey, pkey in [("A", "A"), (psdf.A, pdf.A)]:
              with self.subTest(as_index=as_index, key=pkey):
                  self.assert_eq(
                      sort(
                          psdf.groupby(kkey, as_index=as_index).agg(
                              "sum"
                          )
                      ),
                      sort(
                          pdf.groupby(pkey, as_index=as_index).agg(
                              "sum"
                          )
                      ),
                  )
                  self.assert_eq(
                      sort(
                          psdf.groupby(kkey, as_index=as_index).agg(
                              {"B": "min", "C": "sum"}
                          )
                      ),
                      sort(
                          pdf.groupby(pkey, as_index=as_index).agg(
                              {"B": "min", "C": "sum"}
                          )
                      ),
                  )
                  self.assert_eq(
                      sort(
                          psdf.groupby(kkey, as_index=as_index).agg(
                              {"B": ["min", "max"], "C": "sum"}
                          )
                      ),
                      sort(
                          pdf.groupby(pkey, as_index=as_index).agg(
                              {"B": ["min", "max"], "C": "sum"}
                          )
                      ),
                  )
  
                  if as_index:
                      self.assert_eq(
                          sort(
                              psdf.groupby(kkey, as_index=as_index).agg(
                                  ["sum"]
                              )
                          ),
                          sort(
                              pdf.groupby(pkey, as_index=as_index).agg(
                                  ["sum"]
                              )
                          ),
                      )
                  else:
                      # seems like a pandas' bug for as_index=False and func_or_funcs is list?
                      self.assert_eq(
                          sort(
                              psdf.groupby(kkey, as_index=as_index).agg(
                                  ["sum"]
                              )
                          ),
                          sort(
                              pdf.groupby(pkey, as_index=True)
                              .agg(["sum"])
                              .reset_index()
                          ),
                      )
  
          for kkey, pkey in [
              (psdf.A + 1, pdf.A + 1),
              (psdf.copy().A, pdf.copy().A),
          ]:
              with self.subTest(as_index=as_index, key=pkey):
                  self.assert_eq(
                      sort(
                          psdf.groupby(kkey, as_index=as_index).agg(
                              "sum"
                          )
                      ),
                      sort(
                          pdf.groupby(pkey, as_index=as_index).agg(
                              "sum"
                          )
                      ),
                  )
                  self.assert_eq(
                      sort(
                          psdf.groupby(kkey, as_index=as_index).agg(
                              {"B": "min", "C": "sum"}
                          )
                      ),
                      sort(
                          pdf.groupby(pkey, as_index=as_index).agg(
                              {"B": "min", "C": "sum"}
                          )
                      ),
                  )
                  self.assert_eq(
                      sort(
                          psdf.groupby(kkey, as_index=as_index).agg(
                              {"B": ["min", "max"], "C": "sum"}
                          )
                      ),
                      sort(
                          pdf.groupby(pkey, as_index=as_index).agg(
                              {"B": ["min", "max"], "C": "sum"}
                          )
                      ),
                  )
                  self.assert_eq(
                      sort(
                          psdf.groupby(kkey, as_index=as_index).agg(
                              ["sum"]
                          )
                      ),
                      sort(
                          pdf.groupby(pkey, as_index=as_index).agg(
                              ["sum"]
                          )
                      ),
                  )
  
      expected_error_message = (
          r"aggs must be a dict mapping from column name to aggregate functions "
          r"\(string or list of strings\)."
      )
      with self.assertRaisesRegex(ValueError, expected_error_message):
          psdf.groupby("A", as_index=as_index).agg(0)
  
      # multi-index columns
      columns = pd.MultiIndex.from_tuples(
          [(10, "A"), (10, "B"), (20, "C")]
      )
      pdf.columns = columns
      psdf.columns = columns
  
      for as_index in [True, False]:
          stats_psdf = psdf.groupby((10, "A"), as_index=as_index).agg(
              {(10, "B"): "min", (20, "C"): "sum"}
          )
          stats_pdf = pdf.groupby((10, "A"), as_index=as_index).agg(
              {(10, "B"): "min", (20, "C"): "sum"}
          )
          self.assert_eq(
              stats_psdf.sort_values(
                  by=[(10, "B"), (20, "C")]
              ).reset_index(drop=True),
              stats_pdf.sort_values(
                  by=[(10, "B"), (20, "C")]
              ).reset_index(drop=True),
          )
  
      stats_psdf = psdf.groupby((10, "A")).agg(
          {(10, "B"): ["min", "max"], (20, "C"): "sum"}
      )
      stats_pdf = pdf.groupby((10, "A")).agg(
          {(10, "B"): ["min", "max"], (20, "C"): "sum"}
      )
      self.assert_eq(
          stats_psdf.sort_values(
              by=[(10, "B", "min"), (10, "B", "max"), (20, "C", "sum")]
          ).reset_index(drop=True),
          stats_pdf.sort_values(
              by=[(10, "B", "min"), (10, "B", "max"), (20, "C", "sum")]
          ).reset_index(drop=True),
      )
  
      # non-string names
      pdf.columns = [10, 20, 30]
      psdf.columns = [10, 20, 30]
  
      for as_index in [True, False]:
          stats_psdf = psdf.groupby(10, as_index=as_index).agg(
              {20: "min", 30: "sum"}
          )
          stats_pdf = pdf.groupby(10, as_index=as_index).agg(
              {20: "min", 30: "sum"}
          )
          self.assert_eq(
              stats_psdf.sort_values(by=[20, 30]).reset_index(
                  drop=True
              ),
              stats_pdf.sort_values(by=[20, 30]).reset_index(drop=True),
          )
  
      stats_psdf = psdf.groupby(10).agg({20: ["min", "max"], 30: "sum"})
      stats_pdf = pdf.groupby(10).agg({20: ["min", "max"], 30: "sum"})
      self.assert_eq(
          stats_psdf.reset_index(drop=True),
          stats_pdf.reset_index(drop=True),
      )
  
file_path: spark/python/pyspark/pandas/tests/groupby/test_aggregate.py
imports: import unittest
  import pandas
  from pyspark import pandas
  from pyspark.testing.pandasutils import ComparisonTestBase
  from pyspark.testing.sqlutils import SQLTestUtils
label_desc: Use image node_id 1 for calling the GroupbyAggregateMixin obj's underlying member method code with example usage: obj.test_aggregate() and returns: df, df