code: def apply(self, func, shortcut=False, args=(), **kwargs):
          
          if shortcut:
              grouped = self._iter_grouped_shortcut()
          else:
              grouped = self._iter_grouped()
          applied = (maybe_wrap_array(arr, func(arr, *args, **kwargs))
                     for arr in grouped)
          return self._combine(applied, shortcut=shortcut)
docs: Apply a function over each array in the group and concatenate them
          together into a new array.
  
          `func` is called like `func(ar, *args, **kwargs)` for each array `ar`
          in this group.
  
          Apply uses heuristics (like `pandas.GroupBy.apply`) to figure out how
          to stack together the array. The rule is:
          1. If the dimension along which the group coordinate is defined is
             still in the first grouped array after applying `func`, then stack
             over this dimension.
          2. Otherwise, stack over the new dimension given by name of this
             grouping (the argument to the `groupby` function).
  
          Parameters
          ----------
          func : function
              Callable to apply to each array.
          shortcut : bool, optional
              Whether or not to shortcut evaluation under the assumptions that:
              (1) The action of `func` does not depend on any of the array
                  metadata (attributes or coordinates) but only on the data and
                  dimensions.
              (2) The action of `func` creates arrays with homogeneous metadata,
                  that is, with the same dimensions and attributes.
              If these conditions are satisfied `shortcut` provides significant
              speedup. This should be the case for many common groupby operations
              (e.g., applying numpy ufuncs).
          args : tuple, optional
              Positional arguments passed to `func`.
          **kwargs
              Used to call `func(ar, **kwargs)` for each array `ar`.
  
          Returns
          -------
          applied : DataArray or DataArray
              The result of splitting, applying and combining this array.