-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: groupby with CategoricalIndex doesn't include unobserved categories #49373
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
Conversation
No problem! I think this should pretty much cover the changes in #49318 so will close my PR. |
@@ -542,6 +537,14 @@ def __init__( | |||
# TODO 2022-10-08 we only have one test that gets here and | |||
# values are already in nanoseconds in that case. | |||
self.grouping_vector = Series(self.grouping_vector).to_numpy() | |||
elif is_categorical_dtype(self.grouping_vector): |
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.
any particular reason this was moved from above?
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.
Previously, this block was in an if...elif...elif...
chain where it would be skipped over when the first if was true (namely, when the grouping is specified by a level in the index). Now it's moved out of that chain, so it's always hit when appropriate.
@@ -1235,10 +1289,10 @@ def df_cat(df): | |||
@pytest.mark.parametrize("operation", ["agg", "apply"]) | |||
def test_seriesgroupby_observed_true(df_cat, operation): | |||
# GH 24880 |
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.
Nit: Could you add the GH reference related to why this test changed?
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.
Done.
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.
One small comment otherwise LGTM
…pby_cat_unobserved
…h/pandas into groupby_cat_unobserved
Thanks @rhshadrach |
…ies (pandas-dev#49373) * BUG: groupby with CategoricalIndex doesn't include unobserved categories * Test fixup * cleanup * Remove TODO * Add GH reference * Add GH reference
…ies (pandas-dev#49373) * BUG: groupby with CategoricalIndex doesn't include unobserved categories * Test fixup * cleanup * Remove TODO * Add GH reference * Add GH reference
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.@gt-on-1234 - my apologies here; I was meaning to just tackle #49354 but found that my changes leaked over into #49223. Take a look and let me know what you think.