Skip to content

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

Merged
merged 4 commits into from
Apr 17, 2020
Merged

Conversation

mojones
Copy link
Contributor

@mojones mojones commented Apr 16, 2020

Added test to ensure that categories stay ordered when grouping
with missing values.

Added test to ensure that categories stay ordered when grouping
with missing values.
@pep8speaks
Copy link

pep8speaks commented Apr 16, 2020

Hello @mojones! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-04-17 08:44:02 UTC

Copy link
Member

@simonjayhawkins simonjayhawkins left a 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.

@@ -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():
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, will do

dtype="category",
)

result = df.groupby(["bar", "foo"]).size().unstack()
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

@simonjayhawkins simonjayhawkins added the Testing pandas testing functions or related to the test suite label Apr 16, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Apr 16, 2020
@jreback jreback added Categorical Categorical Data Type Groupby labels Apr 17, 2020
@jreback jreback merged commit c8db9b9 into pandas-dev:master Apr 17, 2020
@jreback
Copy link
Contributor

jreback commented Apr 17, 2020

thanks @mojones very nice.

happy to take a test for #23865 as well

CloseChoice pushed a commit to CloseChoice/pandas that referenced this pull request Apr 20, 2020
rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Groupby Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing values in ordered category breaks sorting of unstacked columns
4 participants