-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: added test for GH28597 #33588
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
TST: added test for GH28597 #33588
Conversation
Added test to ensure that categories stay ordered when grouping with missing values.
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.
@mojones Thanks for the PR.
pandas/tests/groupby/test_groupby.py
Outdated
@@ -2012,3 +2012,48 @@ def test_groups_repr_truncates(max_seq_items, expected): | |||
|
|||
result = df.groupby(np.array(df.a)).groups.__repr__() | |||
assert result == expected | |||
|
|||
|
|||
def test_sorted_missing_category_values(): |
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.
can you move this test to pandas/tests/groupby/test_categorical.py
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.
No problem, will do
pandas/tests/groupby/test_groupby.py
Outdated
dtype="category", | ||
) | ||
|
||
result = df.groupby(["bar", "foo"]).size().unstack() |
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.
I think the change in behaviour that needs to be tested is the size method and the unstack call is not relevant in the issue OP.
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.
There are two separate issues that have been fixed, and I think that this tests them both. One is that missing categorical values in groupby
would cause the categories to become unsorted #28597 . That is the one that I have mentioned in the commit message.
The other is that previously, empty groups would be missing from the output even when grouping with categories #23865, which I think this test also catches as a side effect.
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.
IIUC it's the size call that is the root cause of the issues and this issue was resolved in #29690
which I think this test also catches as a side effect
maybe one of the issues should be closed as a duplicate?
Added test to ensure that categories stay ordered when grouping
with missing values.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff