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 · Fixed by #24850
Closed

Exception when grouping on a modified category #24740

phil65 opened this issue Jan 12, 2019 · 4 comments · Fixed by #24850
Labels
Bug Categorical Categorical Data Type Groupby
Milestone

Comments

@phil65
Copy link

phil65 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
Copy link
Member

@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)

@jorisvandenbossche jorisvandenbossche added the Needs Info Clarification about behavior needed to assess issue label Jan 12, 2019
@phil65
Copy link
Author

phil65 commented Jan 12, 2019

Sure. Done.

@jorisvandenbossche jorisvandenbossche added Bug Groupby Categorical Categorical Data Type and removed Needs Info Clarification about behavior needed to assess issue labels Jan 12, 2019
@jorisvandenbossche jorisvandenbossche added this to the Contributions Welcome milestone Jan 12, 2019
@jorisvandenbossche
Copy link
Member

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
Copy link
Member

This is certainly related: #21151

@jreback jreback modified the milestones: Contributions Welcome, 0.24.0 Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants