-
-
Couldn't load subscription status.
- Fork 2.7k
Fix KeyError when using column of pd.Categorical dtype with unobserved categories #4437
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
Fix KeyError when using column of pd.Categorical dtype with unobserved categories #4437
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💃 Thanks @arcanaxion, your fix looks great, and thanks so much for the clean & clear test.
CI failure looks flaky, I've rerun it. Would you add a changelog entry, then we can merge?
Thanks @alexcjohnson! Just added a changelog entry. Will this do?
Thank you for this PR @arcanaxion
The community's support in building new features or fixing bugs is of great importance and very much appreciated. If there is anything else that catches your eye, let us know.
This PR passes
observed=Trueto omit categorical values with no observations in the dataset. Fixes #4274 and #4433.Also silences the FutureWarning from pandas-dev/pandas#43999 since pandas 2.1 that the default of
observed=Falsewill be changed toTruein a future version.Following code raises
KeyError: 'Fri'before this fix: