When agg fails the error is cached?
Sorry if this is too hard to reproduce. It is driving me crazy.

#### Code Sample, a copy-pastable example if possible

```python
# This works fine
data.head(2245675).groupby(level = 'id', sort = False).agg(['count'])
# This fails (If someone can help me debug why I would appreciate it but is not the issue I'm reporting, error is pasted below)
data.head(2245676).groupby(level = 'id', sort = False).agg(['count'])
# Now I get the head of data
data2 = data.head(5)
# This works ok
data2.groupby(level = 'id', sort = False).count()
# but this FAILS!
data2.groupby(level = 'id', sort = False).agg(['count'])
```
#### Problem description

It seems agg is caching something and that makes things very difficult to debug because it fails with a very simple dataframe where count works fine.

In the following section I'm pasting the error, I don't know why the error happens, if you can help me determine what in my data can cause this error then thank you!

#### The error

```python
Traceback (most recent call last)
<ipython-input-116-b422fc0967b1> in <module>()
----> 4 df.groupby(level = 'id', sort = False).agg(['count'])

/home/user/anaconda3/lib/python3.6/site-packages/pandas/core/groupby.py in aggregate(self, func_or_funcs, *args, **kwargs)
   2798         if hasattr(func_or_funcs, '__iter__'):
   2799             ret = self._aggregate_multiple_funcs(func_or_funcs,
-> 2800                                                  (_level or 0) + 1)
   2801         else:
   2802             cyfunc = self._is_cython_func(func_or_funcs)

/home/user/anaconda3/lib/python3.6/site-packages/pandas/core/groupby.py in _aggregate_multiple_funcs(self, arg, _level)
   2867             # reset the cache so that we
   2868             # only include the named selection
-> 2869             if name in self._selected_obj:
   2870                 obj = copy.copy(obj)
   2871                 obj._reset_cache()

/home/user/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in __contains__(self, key)
    905     def __contains__(self, key):
    906         """True if the key is in the info axis"""
--> 907         return key in self._info_axis
    908 
    909     @property

/home/user/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/multi.py in __contains__(self, key)
   1326         hash(key)
   1327         try:
-> 1328             self.get_loc(key)
   1329             return True
   1330         except LookupError:

/home/user/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/multi.py in get_loc(self, key, method)
   1964 
   1965         if not isinstance(key, tuple):
-> 1966             loc = self._get_level_indexer(key, level=0)
   1967             return _maybe_to_slice(loc)
   1968 

/home/user/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/multi.py in _get_level_indexer(self, key, level, indexer)
   2227         else:
   2228 
-> 2229             loc = level_index.get_loc(key)
   2230             if isinstance(loc, slice):
   2231                 return loc

/home/user/anaconda3/lib/python3.6/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2391             key = _values_from_object(key)
   2392             try:
-> 2393                 return self._engine.get_loc(key)
   2394             except KeyError:
   2395                 return self._engine.get_loc(self._maybe_cast_indexer(key))

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5239)()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:4881)()

pandas/_libs/index.pyx in pandas._libs.index._bin_search (pandas/_libs/index.c:8637)()

TypeError: '<' not supported between instances of 'numpy.ndarray' and 'str'
```


#### Output of ``pd.show_versions()``
[paste the output of ``pd.show_versions()`` here below this line]
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.10.0-28-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.1
pytest: 3.0.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 5.3.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.3
bs4: 4.6.0
html5lib: 0.999
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

</details>
