Unexpected behavior with groupby on single-row dataframe? #11741

Closed
dwyatte opened this Issue Dec 2, 2015 · 3 comments

Comments

Projects
None yet
3 participants

dwyatte commented Dec 2, 2015

Do single-row dataframes (not series) get special treatment in some way? It seems you can do arbitrary groupby operations on them on non-existent columns without errors.

df1 = pd.DataFrame(np.random.randn(1,4), columns=list('ABCD'))
df2 = pd.DataFrame(np.random.randn(2,4), columns=list('ABCD'))

In [3]: df1.groupby('asdf')
Out[3]: pandas.core.groupby.DataFrameGroupBy object at 0x1139acb10

In [4]: df2.groupby('asdf')
KeyError: 'asdf'
Contributor

nbonnotte commented Jan 16, 2016

Yeah, there is a problem. I discovered that while working on issue #11640

I've a PR ready

Contributor

nbonnotte commented Jan 16, 2016

Solved with PR #12063

jreback added the Groupby label Jan 16, 2016

jreback added this to the 0.18.0 milestone Jan 16, 2016

jreback added the Bug label Jan 16, 2016

@nbonnotte nbonnotte added a commit to nbonnotte/pandas that referenced this issue Jan 16, 2016

@nbonnotte nbonnotte BUG in .groupby for single-row DF
No KeyError was raised when grouping by a non-existant column

Fixes #11741

Xref issue #11640, PR #11717
a5c4555

jreback closed this in e9e8598 Jan 17, 2016

dwyatte commented Jan 19, 2016

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment