-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DataFrame.groupby(grp, axis=1) with categorical grp breaks #13420
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
Your grouper is not a valid categorical as it doesn't map anything. Though this still fails.
So i'd say this is a bug, but need a bit of workout on the tests. |
That's great! A question for your answer, though: You say that
What do you mean by this? The counter-example shown above has the categories given explicitly, but the first example (giving only values) should work fine, as the categories, if not given, are assumed to be the unique values of values.. What am I missing? Small demo of codes and categories from first example
Thank you for your work! |
the problem in your example is that nothing maps but you are mapping integers - I don't think we error on this but everything gets into the man group and it should return an empty frame I think |
This is in fact related to grouping by categories. Here is an example:
|
While attempting to use
pd.qcut
(which returned a Categorical) to bin some data in groups for plotting, I encountered the following error. The idea is to group a DataFrame by columns (axis=1
) using a Categorical.Minimal breaking example
Expected behaviour
Same as
So, it works as expected when doubly transposed. This makes it appear as a bug to me.
Proposed solution
In
if is_categorical_dtype(gpr) and len(gpr) != len(obj):
, changelen(obj)
toobj.shape[axis]
. This assumes thatlen(obj) == obj.shape[0]
for allobj
.So, supposing you agree that this is a bug, should a test be put in
test_groupby_categorical
?output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: