-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: added test for missing categories for value_counts
#54837
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
rsm-23
commented
Aug 29, 2023
•
edited
Loading
edited
- closes TST: Add tests for DataFrame/Series.value_counts with missing categories #54836
- Tests added and passed if fixing a bug or adding a new feature
- All code checks passed.
@rhshadrach can you please review this PR? |
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 for the PR!
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 for the update! A small request to make the test a little simpler.
expected = pd.Series( | ||
1, | ||
index=pd.MultiIndex.from_arrays( | ||
[pd.CategoricalIndex([1, 2, 4], categories=[1, 2, 3, 4], name="a")] | ||
), | ||
name="count", | ||
) | ||
# result should include the missing category | ||
expected[3] = 0 |
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.
Instead of modifying expected
in the last line, it is slightly simpler to specify the correct results up front.
expected = pd.Series(
[1, 1, 1, 0],
index=pd.MultiIndex.from_arrays(
[pd.CategoricalIndex([1, 2, 4, 3], categories=[1, 2, 3, 4], name="a")]
),
name="count",
)
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 for the suggestion @rhshadrach . I have made the change.
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.
@rhshadrach can you please take a look?
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.
lgtm
Thanks @rsm-23 |