class_docstr: Groupby-specific tests.
class_docstr_tok: ["Groupby-specific","tests","."]
code: def test_groupby_extension_agg(self, as_index, data_for_grouping):
      df = pd.DataFrame(
          {"A": [1, 1, 2, 2, 3, 3, 1, 4], "B": data_for_grouping}
      )
  
      is_bool = data_for_grouping.dtype._is_boolean
      if is_bool:
          # only 2 unique values, and the final entry has c==b
          #  (see data_for_grouping docstring)
          df = df.iloc[:-1]
  
      result = df.groupby("B", as_index=as_index).A.mean()
      _, uniques = pd.factorize(data_for_grouping, sort=True)
  
      exp_vals = [3.0, 1.0, 4.0]
      if is_bool:
          exp_vals = exp_vals[:-1]
      if as_index:
          index = pd.Index(uniques, name="B")
          expected = pd.Series(exp_vals, index=index, name="A")
          tm.assert_series_equal(result, expected)
      else:
          expected = pd.DataFrame({"B": uniques, "A": exp_vals})
          tm.assert_frame_equal(result, expected)
  
file_path: pandas/pandas/tests/extension/base/groupby.py
imports: import re
  import pytest
  from pandas.core.dtypes.common import is_bool_dtype, is_numeric_dtype, is_object_dtype, is_string_dtype
  import pandas
  import pandas._testing
label_desc: Use image node_id 2 for calling the BaseGroupbyTests obj's underlying member method code with example usage: obj.test_groupby_extension_agg(as_index, data_for_grouping) without return types