# Buggy code
def __getitem__(self, key):
    if self._selection is not None:
        raise Exception(
            "Column(s) {selection} already selected".format(selection=self._selection)
        )

    if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray)):
        if len(self.obj.columns.intersection(key)) != len(key):
            bad_keys = list(set(key).difference(self.obj.columns))
            raise KeyError(
                "Columns not found: {missing}".format(missing=str(bad_keys)[1:-1])
            )
        return self._gotitem(list(key), ndim=2)

    elif not getattr(self, "as_index", False):
        if key not in self.obj.columns:
            raise KeyError("Column not found: {key}".format(key=key))
        return self._gotitem(key, ndim=2)

    else:
        if key not in self.obj:
            raise KeyError("Column not found: {key}".format(key=key))
        return self._gotitem(key, ndim=1)


# Traceback (Exception)
In [13]: df = pd.DataFrame({"A": pd.to_datetime(['2015', '2017']), "B": [1, 1]})

In [14]: df
Out[14]:
A  B
0 2015-01-01  1
1 2017-01-01  1

In [15]: df.set_index("A").groupby([0, 0]).resample("AS")
Out[15]: DatetimeIndexResamplerGroupby [freq=<YearBegin: month=1>, axis=0, closed=left, label=left, convention=e, base=0]

In [16]: df.set_index("A").groupby([0, 0]).resample("AS").agg(['sum', 'count'])
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-16-5f1c18a8d4ac> in <module>()
----> 1 df.set_index("A").groupby([0, 0]).resample("AS").agg(['sum', 'count'])

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/resample.py in aggregate(self, arg, *args, **kwargs)
339
340         self._set_binner()
--> 341         result, how = self._aggregate(arg, *args, **kwargs)
342         if result is None:
343             result = self._groupby_and_aggregate(arg,

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/base.py in _aggregate(self, arg, *args, **kwargs)
538             return self._aggregate_multiple_funcs(arg,
539                                                   _level=_level,
--> 540                                                   _axis=_axis), None
541         else:
542             result = None

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/base.py in _aggregate_multiple_funcs(self, arg, _level, _axis)
583                 try:
584                     colg = self._gotitem(col, ndim=1, subset=obj[col])
--> 585                     results.append(colg.aggregate(arg))
586                     keys.append(col)
587                 except (TypeError, DataError):

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/resample.py in aggregate(self, arg, *args, **kwargs)
339
340         self._set_binner()
--> 341         result, how = self._aggregate(arg, *args, **kwargs)
342         if result is None:
343             result = self._groupby_and_aggregate(arg,

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/base.py in _aggregate(self, arg, *args, **kwargs)
538             return self._aggregate_multiple_funcs(arg,
539                                                   _level=_level,
--> 540                                                   _axis=_axis), None
541         else:
542             result = None

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/base.py in _aggregate_multiple_funcs(self, arg, _level, _axis)
582             for col in obj:
583                 try:
--> 584                     colg = self._gotitem(col, ndim=1, subset=obj[col])
585                     results.append(colg.aggregate(arg))
586                     keys.append(col)

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/base.py in _gotitem(self, key, ndim, subset)
675                        for attr in self._attributes])
676         self = self.__class__(subset,
--> 677                               groupby=self._groupby[key],
678                               parent=self,
679                               **kwargs)

~/Envs/pandas-dev/lib/python3.6/site-packages/pandas/pandas/core/base.py in __getitem__(self, key)
241         if self._selection is not None:
242             raise Exception('Column(s) {selection} already selected'
--> 243                             .format(selection=self._selection))
244
245         if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass,

Exception: Column(s) B already selected

# Fixed code
def __getitem__(self, key):
    if self._selection is not None:
        raise IndexError(
            "Column(s) {selection} already selected".format(selection=self._selection)
        )

    if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray)):
        if len(self.obj.columns.intersection(key)) != len(key):
            bad_keys = list(set(key).difference(self.obj.columns))
            raise KeyError(
                "Columns not found: {missing}".format(missing=str(bad_keys)[1:-1])
            )
        return self._gotitem(list(key), ndim=2)

    elif not getattr(self, "as_index", False):
        if key not in self.obj.columns:
            raise KeyError("Column not found: {key}".format(key=key))
        return self._gotitem(key, ndim=2)

    else:
        if key not in self.obj:
            raise KeyError("Column not found: {key}".format(key=key))
        return self._gotitem(key, ndim=1)