code: def assert_groupby_equal(
      left,
      right,
      sort_keys=False,
      sort_index=True,
      with_selection=False,
  ):
      if hasattr(left, "groupby_obj"):
          left = left.groupby_obj
      if hasattr(right, "groupby_obj"):
          right = right.groupby_obj
  
      if type(left) is not type(right):
          raise AssertionError(
              f"Type of groupby not consistent: {type(left)} != {type(right)}"
          )
  
      left_selection = getattr(left, "_selection", None)
      right_selection = getattr(right, "_selection", None)
      if sort_keys:
          left = sorted(left, key=lambda p: p[0])
          right = sorted(right, key=lambda p: p[0])
      else:
          left, right = list(left), list(right)
      if sort_index:
          left = [(k, v.sort_index()) for k, v in left]
          right = [(k, v.sort_index()) for k, v in right]
  
      if len(left) != len(right):
          raise AssertionError(
              f"Count of groupby keys not consistent: {len(left)} != {len(right)}"
          )
  
      left_keys = [p[0] for p in left]
      right_keys = [p[0] for p in right]
      if left_keys != right_keys:
          raise AssertionError(
              f"Group keys not consistent: {left_keys!r} != {right_keys!r}"
          )
      for (left_key, left_frame), (right_key, right_frame) in zip(
          left, right
      ):
          if with_selection:
              if left_selection and isinstance(
                  left_frame, pd.DataFrame
              ):
                  left_frame = left_frame[left_selection]
              if right_selection and isinstance(
                  right_frame, pd.DataFrame
              ):
                  right_frame = right_frame[right_selection]
  
          if isinstance(left_frame, pd.DataFrame):
              pd.testing.assert_frame_equal(left_frame, right_frame)
          else:
              pd.testing.assert_series_equal(left_frame, right_frame)
  
imports: import fnmatch
  import functools
  import inspect
  import itertools
  import logging
  import os
  import sys
  import time
  import types
  from typing import Dict
  import numpy
  import pandas
  import pytest
  from ..core.operand import OperandStage
  from ..utils import lazy_import
label_desc: Use image node_id 11 for calling a global function with example usage: assert_groupby_equal(left, right, sort_keys, sort_index, with_selection) without return types