-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: groupby nunique with Categorical and missing categories gives ValueError #11635
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
Comments
cc @behzadnouri |
xref #10694 |
@behzadnouri ah, I already forgot that issue :-) Indeed similar, but not fully related I think. The difference is also that the other issue never worked, while this one worked in 0.16.2 and is a regression due to the new |
the problem is that everything needs special casing for categoricals otherwise it does not work, and has caused a lot of code bloat. these should be fixed by fixing categoricals not patching here and there. here the problem is that the resulting index from groupby on categorical is not same as groupby on anything else, even though i do not see any use case for that: >>> df = DataFrame({'B': [1, 2]})
>>> df['A'] = Categorical(list('XY'), list('WXYZ'))
>>> df
B A
0 1 X
1 2 Y
>>> df.groupby('A').grouper.result_index # why W and Z are in the index?
CategoricalIndex([u'W', u'X', u'Y', u'Z'], categories=[u'W', u'X', u'Y', u'Z'], ordered=False, name=u'A', dtype='category')
>>> df.groupby('A').sum() # what was the gain here?
B
A
W NaN
X 1
Y 2
Z NaN |
@behzadnouri because that's the definition of |
I was about to file a new bug about this |
Oh, OK, I'm not saying anything new: #8559 |
covered / dupe by #8559 |
From SO: http://stackoverflow.com/questions/33775560/how-to-group-categorical-values-in-pandas
This worked in 0.16.2, but is broken in 0.17.0 (it gives ValueError: Wrong number of items passed 2, placement implies 3)
It is related with the fact that not all categories are present in the actual values (due to the slicing).
Probably related with new nunique implementation in 0.16.2 (#10894, #11079)
The text was updated successfully, but these errors were encountered: