code: def groupby(
      cls, dataset, dimensions, container_type, group_type, **kwargs
  ):
      index_dims = [
          dataset.get_dimension(d, strict=True) for d in dimensions
      ]
      element_dims = [
          kdim for kdim in dataset.kdims if kdim not in index_dims
      ]
  
      invalid = [d for d in index_dims if dataset.data[d.name].ndim > 1]
      if invalid:
          if len(invalid) == 1:
              invalid = f"'{invalid[0]}'"
          raise ValueError(
              "Cannot groupby irregularly sampled dimension(s) %s."
              % invalid
          )
  
      group_kwargs = {}
      if group_type != "raw" and issubclass(group_type, Element):
          group_kwargs = dict(
              util.get_param_values(dataset), kdims=element_dims
          )
      group_kwargs.update(kwargs)
  
      drop_dim = any(
          d not in group_kwargs["kdims"] for d in element_dims
      )
  
      group_by = [d.name for d in index_dims]
      data = []
      if len(dimensions) == 1:
          for k, v in dataset.data.groupby(index_dims[0].name):
              if drop_dim:
                  v = v.to_dataframe().reset_index()
              data.append((k, group_type(v, **group_kwargs)))
      else:
          unique_iters = [
              cls.values(dataset, d, False) for d in group_by
          ]
          indexes = zip(*util.cartesian_product(unique_iters))
          for k in indexes:
              sel = dataset.data.sel(**dict(zip(group_by, k)))
              if drop_dim:
                  sel = sel.to_dataframe().reset_index()
              data.append((k, group_type(sel, **group_kwargs)))
  
      if issubclass(container_type, NdMapping):
          with item_check(False), sorted_context(False):
              return container_type(data, kdims=index_dims)
      else:
          return container_type(data)
  
imports: import sys
  import types
  import numpy
  import pandas
  from ..None import util
  from ..dimension import Dimension, asdim, dimension_name
  from ..element import Element
  from ..ndmapping import NdMapping, item_check, sorted_context
  from .grid import GridInterface
  from .interface import DataError, Interface
  from .util import dask_array_module, finite_range
label_desc: Use image node_id 12 for calling the XArrayInterface obj's underlying member method code with example usage: obj.groupby(cls, dataset, dimensions, container_type, group_type) and returns: container_type, container_type