code: def test_aggregate_by(self):
      ht = hl.utils.range_table(4)
      ht = ht.annotate(
          foo=0, group=ht.idx < 2, bar="hello"
      ).annotate_globals(glob=5)
      grouped = ht.group_by(ht.group)
      result = grouped.aggregate(
          sum=hl.agg.sum(ht.idx + ht.glob) + ht.glob - 15,
          max=hl.agg.max(ht.idx),
      )
  
      expected = (
          hl.Table.parallelize(
              [
                  {"group": True, "sum": 1, "max": 1},
                  {"group": False, "sum": 5, "max": 3},
              ],
              hl.tstruct(group=hl.tbool, sum=hl.tint64, max=hl.tint32),
          )
          .annotate_globals(glob=5)
          .key_by("group")
      )
  
      self.assertTrue(result._same(expected))
  
      with self.assertRaises(ValueError):
          grouped.aggregate(group=hl.agg.sum(ht.idx))
  
imports: import unittest
  import hail
  from ..helpers import qobtest
label_desc: Use image node_id 1 for calling the GroupedTableTests obj's underlying member method code with example usage: obj.test_aggregate_by() without return types