Skip to content

nunique aggerigation failes on empty frames #14578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
redsum opened this issue Nov 3, 2016 · 5 comments
Closed

nunique aggerigation failes on empty frames #14578

redsum opened this issue Nov 3, 2016 · 5 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Groupby

Comments

@redsum
Copy link

redsum commented Nov 3, 2016

A small, complete example of the issue

# Your code here
df = pd.DataFrame(columns=['a','b','c'])    
df.groupby('a',as_index=False).agg({'b':'nunique'})

Expected Output

We shouldn't get an Exception

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Darwin OS-release: 16.0.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.None

pandas: 0.19.0
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.25.1
numpy: 1.11.2
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.8
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.7
blosc: None
bottleneck: 1.1.0
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.4.0
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.9
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.43.0
pandas_datareader: None

i get the following output

Traceback (most recent call last):
File "/Users/ilangadassi/Documents/workspace/python/MyTests/test1.py", line 75, in
testDfGroup()
File "/Users/ilangadassi/Documents/workspace/python/MyTests/test1.py", line 71, in testDfGroup
df.groupby('a',as_index=False).agg({'b':'nunique'})
File "/Users/ilangadassi/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 3774, in aggregate
return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)
File "/Users/ilangadassi/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 3272, in aggregate
result, how = self._aggregate(arg, _level=_level, *args, **kwargs)
File "/Users/ilangadassi/anaconda/lib/python2.7/site-packages/pandas/core/base.py", line 549, in _aggregate
result = _agg(arg, _agg_1dim)
File "/Users/ilangadassi/anaconda/lib/python2.7/site-packages/pandas/core/base.py", line 500, in _agg
result[fname] = func(fname, agg_how)
File "/Users/ilangadassi/anaconda/lib/python2.7/site-packages/pandas/core/base.py", line 483, in _agg_1dim
return colg.aggregate(how, _level=(_level or 0) + 1)
File "/Users/ilangadassi/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 2660, in aggregate
return getattr(self, func_or_funcs)(*args, **kwargs)
File "/Users/ilangadassi/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 3023, in nunique
res = out if ids[0] != -1 else out[1:]
IndexError: index 0 is out of bounds for axis 0 with size 0

@jreback jreback added this to the No action milestone Nov 3, 2016
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Nov 3, 2016
@jreback
Copy link
Contributor

jreback commented Nov 3, 2016

duplicate of #12553

there is a PR #12560 which is stalled if you'd like to pick it up

@jreback jreback closed this as completed Nov 3, 2016
@redsum
Copy link
Author

redsum commented Nov 4, 2016

@jreback , what do you mean by pick it up ?
do u want me to suggest a fix ?
the fix in PR #12560 , looks good

@jorisvandenbossche
Copy link
Member

@redsum With pick it up, we mean to continue the work that is still needed on PR #12560 to get this merged (see the comments over there. Among other things, there are still tests failing)

@redsum
Copy link
Author

redsum commented Nov 7, 2016

Hi @jreback
i have made the changes.
run the tests
how do i push the changes?

@jorisvandenbossche
Copy link
Member

See http://pandas.pydata.org/pandas-docs/stable/contributing.html#pushing-your-changes on pushing your changes and making a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Groupby
Projects
None yet
Development

No branches or pull requests

3 participants