# Buggy code
def aggregate(self, func, *args, **kwargs):
    _level = kwargs.pop("_level", None)

    relabeling = func is None and _is_multi_agg_with_relabel(**kwargs)
    if relabeling:
        func, columns, order = _normalize_keyword_aggregation(kwargs)

        kwargs = {}
    elif func is None:
        # nicer error message
        raise TypeError("Must provide 'func' or tuples of '(column, aggfunc).")

    func = _maybe_mangle_lambdas(func)

    result, how = self._aggregate(func, _level=_level, *args, **kwargs)
    if how is None:
        return result

    if result is None:
        # grouper specific aggregations
        if self.grouper.nkeys > 1:
            return self._python_agg_general(func, *args, **kwargs)
        else:
            # try to treat as if we are passing a list
            try:
                assert not args and not kwargs
                result = self._aggregate_multiple_funcs(
                    [func], _level=_level, _axis=self.axis
                )

                result.columns = Index(
                    result.columns.levels[0], name=self._selected_obj.columns.name
                )

                if isinstance(self.obj, SparseDataFrame):
                    # Backwards compat for groupby.agg() with sparse
                    # values. concat no longer converts DataFrame[Sparse]
                    # to SparseDataFrame, so we do it here.
                    result = SparseDataFrame(result._data)
            except Exception:
                result = self._aggregate_generic(func, *args, **kwargs)

    if not self.as_index:
        self._insert_inaxis_grouper_inplace(result)
        result.index = np.arange(len(result))

    if relabeling:
        result = result[order]
        result.columns = columns

    return result._convert(datetime=True)


# Traceback (KeyError)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-58-5b7e2c8bacf8> in <module>
3 df = pd.DataFrame({"A": [1, 2]})
4
----> 5 df.groupby([1, 1]).agg(foo=('A', lambda x: x.max()), bar=("A", lambda x: x.min()))

~\AppData\Local\Continuum\anaconda3\envs\insight\lib\site-packages\pandas\core\groupby\generic.py in aggregate(self, arg, *args, **kwargs)
1453     @Appender(_shared_docs["aggregate"])
1454     def aggregate(self, arg=None, *args, **kwargs):
-> 1455         return super().aggregate(arg, *args, **kwargs)
1456
1457     agg = aggregate

~\AppData\Local\Continuum\anaconda3\envs\insight\lib\site-packages\pandas\core\groupby\generic.py in aggregate(self, func, *args, **kwargs)
262
263         if relabeling:
--> 264             result = result[order]
265             result.columns = columns
266

~\AppData\Local\Continuum\anaconda3\envs\insight\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2979             if is_iterator(key):
2980                 key = list(key)
-> 2981             indexer = self.loc._convert_to_indexer(key, axis=1, raise_missing=True)
2982
2983         # take() does not accept boolean indexers

~\AppData\Local\Continuum\anaconda3\envs\insight\lib\site-packages\pandas\core\indexing.py in _convert_to_indexer(self, obj, axis, is_setter, raise_missing)
1269                 # When setting, missing keys are not allowed, even with .loc:
1270                 kwargs = {"raise_missing": True if is_setter else raise_missing}
-> 1271                 return self._get_listlike_indexer(obj, axis, **kwargs)[1]
1272         else:
1273             try:

~\AppData\Local\Continuum\anaconda3\envs\insight\lib\site-packages\pandas\core\indexing.py in _get_listlike_indexer(self, key, axis, raise_missing)
1076
1077         self._validate_read_indexer(
-> 1078             keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
1079         )
1080         return keyarr, indexer

~\AppData\Local\Continuum\anaconda3\envs\insight\lib\site-packages\pandas\core\indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing)
1161                 raise KeyError(
1162                     "None of [{key}] are in the [{axis}]".format(
-> 1163                         key=key, axis=self.obj._get_axis_name(axis)
1164                     )
1165                 )

KeyError: "None of [MultiIndex([('A', '<lambda>'),\n            ('A', '<lambda>')],\n           )] are in the [columns]"

# Fixed code
def aggregate(self, func, *args, **kwargs):
    _level = kwargs.pop("_level", None)

    relabeling = func is None and _is_multi_agg_with_relabel(**kwargs)
    if relabeling:
        func, columns, order = _normalize_keyword_aggregation(kwargs)

        kwargs = {}
    elif func is None:
        # nicer error message
        raise TypeError("Must provide 'func' or tuples of '(column, aggfunc).")

    func = _maybe_mangle_lambdas(func)

    result, how = self._aggregate(func, _level=_level, *args, **kwargs)
    if how is None:
        return result

    if result is None:
        # grouper specific aggregations
        if self.grouper.nkeys > 1:
            return self._python_agg_general(func, *args, **kwargs)
        else:
            # try to treat as if we are passing a list
            try:
                assert not args and not kwargs
                result = self._aggregate_multiple_funcs(
                    [func], _level=_level, _axis=self.axis
                )

                result.columns = Index(
                    result.columns.levels[0], name=self._selected_obj.columns.name
                )

                if isinstance(self.obj, SparseDataFrame):
                    # Backwards compat for groupby.agg() with sparse
                    # values. concat no longer converts DataFrame[Sparse]
                    # to SparseDataFrame, so we do it here.
                    result = SparseDataFrame(result._data)
            except Exception:
                result = self._aggregate_generic(func, *args, **kwargs)

    if not self.as_index:
        self._insert_inaxis_grouper_inplace(result)
        result.index = np.arange(len(result))

    if relabeling:
        # used reordered index of columns
        result = result.iloc[:, order]
        result.columns = columns

    return result._convert(datetime=True)