Skip to content
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

Exception when grouping on a modified category #24740

Closed
phil65 opened this issue Jan 12, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@phil65
Copy link

commented Jan 12, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd

ds = pd.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}) 
ds["b"] = ds["b"].astype("category")
ds['b'].cat.remove_categories(['a'], inplace=True)

# works
ds.groupby("b").groups

# gives ValueError: Categorial categories cannot be null 
ds.groupby("b", observed=True).groups

Problem description

I wonder if that exception should be raised there?
Using 0.24 RC1

Thanks to all working on pandas!

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented Jan 12, 2019

@phil65 Thanks for the report!
Can you provide a more easily reproducible example? Ideally you would construct a small test dataframe with code instead of relying on an external package (eg for adding this test case in the test suite, we don't want to use an external package)

@phil65

This comment has been minimized.

Copy link
Author

commented Jan 12, 2019

Sure. Done.

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented Jan 12, 2019

Thanks!
I can confirm the error on master (existed on 0.23.4 already as well). It also seems that things like a reduction with ds.groupby("b", observed=True).sum() do work (not error). Although they include a NaN in the grouped keys, which doesn't seem to be correct behaviour (and certainly related to the error)

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented Jan 12, 2019

This is certainly related: #21151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.