code: def test_errors_caught_correctly(self):
      from hail.expr.expressions import ExpressionException
  
      mt = self.get_groupable_matrix()
      self.assertRaises(
          ExpressionException, mt.group_rows_by, mt["group1"] + 1
      )
      self.assertRaises(
          ExpressionException, mt.group_cols_by, mt["group1"]
      )
      self.assertRaises(
          ExpressionException, mt.group_cols_by, mt["group3"] + 1
      )
      self.assertRaises(
          ExpressionException, mt.group_rows_by, mt["group3"]
      )
      self.assertRaises(
          ExpressionException, mt.group_rows_by, group3=mt["group1"]
      )
      self.assertRaises(
          ExpressionException, mt.group_cols_by, group1=mt["group3"]
      )
      self.assertRaises(
          ExpressionException, mt.group_rows_by, foo=mt["group1"]
      )
      self.assertRaises(
          ExpressionException, mt.group_cols_by, foo=mt["group3"]
      )
  
      a = mt.group_rows_by(group5=(mt["group2"]["a"] + 1))
      self.assertRaises(
          NotImplementedError,
          a.aggregate_cols,
          bar=hl.agg.sum(mt["col_idx"]),
      )  # cannot aggregate cols when grouped by rows
  
      self.assertRaises(
          ExpressionException,
          a.aggregate_entries,
          group3=hl.agg.sum(mt["c"]),
      )  # duplicate column field
      self.assertRaises(
          ExpressionException,
          a.aggregate_entries,
          group5=hl.agg.sum(mt["c"]),
      )  # duplicate row field
      self.assertRaises(
          ExpressionException,
          a.aggregate_entries,
          foo=hl.agg.sum(mt["c"]),
      )  # duplicate globals field
  
      self.assertRaises(
          ExpressionException,
          a.aggregate_rows,
          group3=hl.agg.sum(mt["row_idx"]),
      )  # duplicate column field
      self.assertRaises(
          ExpressionException,
          a.aggregate_rows,
          group5=hl.agg.sum(mt["row_idx"]),
      )  # duplicate row field
      self.assertRaises(
          ExpressionException,
          a.aggregate_rows,
          foo=hl.agg.sum(mt["row_idx"]),
      )  # duplicate globals field
      self.assertRaises(
          ExpressionException,
          a.aggregate_rows,
          bar=mt["row_idx"] + hl.agg.sum(mt["row_idx"]),
      )  # expression has to have global indices
      self.assertRaises(
          ExpressionException,
          a.aggregate_rows,
          bar=mt["col_idx"] + hl.agg.sum(mt["row_idx"]),
      )  # expression has to have global indices
      self.assertRaises(
          ExpressionException, a.aggregate_rows, bar=hl.agg.sum(mt["c"])
      )  # aggregation scope is rows only - entry field
      self.assertRaises(
          ExpressionException,
          a.aggregate_rows,
          bar=hl.agg.sum(mt["col_idx"]),
      )  # aggregation scope is rows only - column field
  
      b = mt.group_cols_by(group5=(mt["group4"]["a"] + 1))
      self.assertRaises(
          NotImplementedError,
          b.aggregate_rows,
          bar=hl.agg.sum(mt["row_idx"]),
      )  # cannot aggregate rows when grouped by cols
  
      self.assertRaises(
          ExpressionException,
          b.aggregate_entries,
          group1=hl.agg.sum(mt["c"]),
      )  # duplicate row field
      self.assertRaises(
          ExpressionException,
          b.aggregate_entries,
          group5=hl.agg.sum(mt["c"]),
      )  # duplicate column field
      self.assertRaises(
          ExpressionException,
          b.aggregate_entries,
          foo=hl.agg.sum(mt["c"]),
      )  # duplicate globals field
  
      self.assertRaises(
          ExpressionException,
          b.aggregate_cols,
          group1=hl.agg.sum(mt["col_idx"]),
      )  # duplicate row field
      self.assertRaises(
          ExpressionException,
          b.aggregate_cols,
          group5=hl.agg.sum(mt["col_idx"]),
      )  # duplicate column field
      self.assertRaises(
          ExpressionException,
          b.aggregate_cols,
          foo=hl.agg.sum(mt["col_idx"]),
      )  # duplicate globals field
      self.assertRaises(
          ExpressionException,
          b.aggregate_cols,
          bar=mt["col_idx"] + hl.agg.sum(mt["col_idx"]),
      )  # expression has to have global indices
      self.assertRaises(
          ExpressionException,
          b.aggregate_cols,
          bar=mt["row_idx"] + hl.agg.sum(mt["col_idx"]),
      )  # expression has to have global indices
      self.assertRaises(
          ExpressionException, b.aggregate_cols, bar=hl.agg.sum(mt["c"])
      )  # aggregation scope is cols only - entry field
      self.assertRaises(
          ExpressionException,
          b.aggregate_cols,
          bar=hl.agg.sum(mt["row_idx"]),
      )  # aggregation scope is cols only - row field
  
      c = mt.group_rows_by(
          group5=(mt["group2"]["a"] + 1)
      ).aggregate_rows(x=hl.agg.count())
      self.assertRaises(
          ExpressionException, c.aggregate_rows, x=hl.agg.count()
      )  # duplicate field
  
      d = mt.group_cols_by(
          group5=(mt["group4"]["a"] + 1)
      ).aggregate_cols(x=hl.agg.count())
      self.assertRaises(
          ExpressionException, d.aggregate_cols, x=hl.agg.count()
      )
  
file_path: hail/hail/python/test/hail/matrixtable/test_grouped_matrix_table.py
imports: import unittest
  import hail
  from ..helpers import *
label_desc: Use image node_id 3 for calling the Tests obj's underlying member method code with example usage: obj.test_errors_caught_correctly() without return types