wesm/pandas — Issue #421: Buglet in groupby when passing function like len with as_index False
Author: wesm
Created: 2011-11-28 10:45:38+00:00
State: open
Labels: Bug

```
import numpy as np
import pandas

def webuse(data, baseurl='http://www.stata-press.com/data/r11/'):
"""
Parameters
----------
data : str
Name of dataset to fetch.

Examples
--------
>>> dta = webuse('auto')

Notes
-----
Make sure baseurl has trailing forward slash. Doesn't do any
error checking in response URLs.
"""
# lazy imports
from scikits.statsmodels.iolib import genfromdta
from urllib2 import urlopen
from urlparse import urljoin
from StringIO import StringIO

url = urljoin(baseurl, data+'.dta')
dta = urlopen(url)
dta = StringIO(dta.read()) # make it truly file-like
return genfromdta(dta)

dta = webuse('auto')
df = pandas.DataFrame.from_records(dta)
```

then

`df.groupby(['foreign', 'rep78'], as_index=False)['mpg'].agg(len)`

raises an exception