-
-
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
Changes from 13 commits
14eb325
281ae55
0b457ef
17b5aaf
85b1639
a0c3c3e
575a9ca
ef89d64
62ad090
12b49c4
8c52aba
34382db
42ad605
71e1fb8
663c564
ee5ba00
83847b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,33 +164,45 @@ 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 | ||
|
||
groupby_kwargs = {'level': level, 'axis': axis, 'sort': sort, | ||
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. I don't think you actually need to define this kwargs, just inline it when calling frame.groupby(...) no? 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. Ah, good point |
||
'as_index': as_index} | ||
group_op_kwargs = {} | ||
frame_op_kwargs = {'level': level, 'axis': axis} | ||
if op in AGG_FUNCTIONS_WITH_SKIPNA: | ||
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. I think this would be more clear with
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. So remove the idea of 'base arguments'? I thought it might be good to pull out the common arguments but maybe it's more readable the other way. The previous test code just seemed pretty repetitive to me. 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. yeah just trying to make this simpler to read 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. Sounds good, I will clean these tests up a bit and ping when everything is green! |
||
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) | ||
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) | ||
group_op_kwargs['skipna'] = skipna | ||
frame_op_kwargs['skipna'] = skipna | ||
|
||
grouped = frame.groupby(**groupby_kwargs) | ||
result = getattr(grouped, op)(**group_op_kwargs) | ||
expected = getattr(frame, op)(**frame_op_kwargs) | ||
|
||
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): | ||
|
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