-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix #10355, std() groupby calculation #26229
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
Closed
Closed
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
14eb325
BUG: Fix #10355, std() groupby calculation
alexcwatt 281ae55
Add whatsnew note
alexcwatt 0b457ef
Pass ddof to std, remove axis
alexcwatt 17b5aaf
Add back validation
alexcwatt 85b1639
Handle IndexError in _python_agg_general
alexcwatt a0c3c3e
Make requested changes to tests
alexcwatt 575a9ca
Add cython version of groupby std
alexcwatt ef89d64
PEP8 fix
alexcwatt 62ad090
Refactor std and var to reduce complexity
alexcwatt 12b49c4
Don't cactch IndexError
alexcwatt 8c52aba
Begin updating test_regression_whitelist_methods
alexcwatt 34382db
Update test_regression_whitelist_methods, remove specialized test
alexcwatt 42ad605
Resolve PEP8 issue
alexcwatt 71e1fb8
Make test code clearer
alexcwatt 663c564
Merge branch 'master' into fix-10355
alexcwatt ee5ba00
Switch to fixture for axis, add appropriate pytest.skips
alexcwatt 83847b6
Handle case of no bins in reduction.pyx
alexcwatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,33 +164,43 @@ def raw_frame(): | |
@pytest.mark.parametrize('axis', [0, 1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this and it will just use the axis fixture; note that axis will take on [0, 1, 'index', 'columns'], so you may have to adjust some of the test conditions |
||
@pytest.mark.parametrize('skipna', [True, False]) | ||
@pytest.mark.parametrize('sort', [True, False]) | ||
@pytest.mark.parametrize('as_index', [True, False]) | ||
def test_regression_whitelist_methods( | ||
raw_frame, op, level, | ||
axis, skipna, sort): | ||
axis, skipna, sort, as_index): | ||
# GH6944 | ||
# GH 17537 | ||
# explicitly test the whitelist methods | ||
|
||
if not as_index and axis == 1: | ||
pytest.skip('as_index=False only valid for axis=0') | ||
|
||
if axis == 0: | ||
frame = raw_frame | ||
else: | ||
frame = raw_frame.T | ||
|
||
grouped = frame.groupby(level=level, axis=axis, sort=sort, | ||
as_index=as_index) | ||
|
||
if op in AGG_FUNCTIONS_WITH_SKIPNA: | ||
grouped = frame.groupby(level=level, axis=axis, sort=sort) | ||
result = getattr(grouped, op)(skipna=skipna) | ||
expected = getattr(frame, op)(level=level, axis=axis, | ||
skipna=skipna) | ||
if sort: | ||
expected = expected.sort_index(axis=axis, level=level) | ||
tm.assert_frame_equal(result, expected) | ||
expected = getattr(frame, op)(level=level, axis=axis, skipna=skipna) | ||
else: | ||
grouped = frame.groupby(level=level, axis=axis, sort=sort) | ||
result = getattr(grouped, op)() | ||
expected = getattr(frame, op)(level=level, axis=axis) | ||
if sort: | ||
expected = expected.sort_index(axis=axis, level=level) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
if sort: | ||
expected = expected.sort_index(axis=axis, level=level) | ||
|
||
if not as_index: | ||
expected = expected.reset_index() | ||
if level == 0: | ||
expected = expected.drop(columns=['first']) | ||
if level == 1: | ||
expected = expected.drop(columns=['second']) | ||
|
||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_groupby_blacklist(df_letters): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
use double back ticks around
as_index=False