-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: organize and cleanup pandas/tests/groupby/test_aggregate.py #18931
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
Codecov Report
@@ Coverage Diff @@
## master #18931 +/- ##
==========================================
- Coverage 91.58% 91.58% -0.01%
==========================================
Files 150 150
Lines 48972 48972
==========================================
- Hits 44851 44849 -2
- Misses 4121 4123 +2
Continue to review full report at Codecov.
|
thanks @alysivji can you split things out to new files? IOW each of these classes to a separate file, something like
just to make this even more organized. be sure to add a |
@jreback lemme know if anything else needs to be done. Thanks! |
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.
@alysivji looking good. some requests to parameterize. could completely eliminate the need for the setup method in aggregate/test_aggregate.py if you want to make those into fixtures instead. can do this in another PR if you want.
expected = grouped.mean() | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_aggregate_str_func(self): |
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 parametrize this (on by_weekday and by_mwkday)
df['E'] = ['a'] * len(self.df) | ||
grouped = self.df.groupby('A') | ||
|
||
# API change in 0.11 |
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 remove this commented out
|
||
class TestGroupByAggregateCython(object): | ||
|
||
def test_cythonized_aggers(self): |
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 parameterize this
tm.assert_series_equal(summed, expected) | ||
|
||
def test__cython_agg_general(self): | ||
ops = [('mean', np.mean), |
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 parameterize
exc.args += ('operation: %s' % op, ) | ||
raise | ||
|
||
def test_cython_agg_empty_buckets(self): |
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.
same
cc @TomAugspurger I think we have to merge #18921 (when ready) before this (and rebase this on master)? |
Yes it'd be nice to merge #18921 before this. Backporting can be tricky when files are split. |
@alysivji but go ahead and make the changes as above when you can. we will be merging @TomAugspurger soon anyhow. |
@jreback Changes have been made. Also deleted the cython test class, not needed anymore since it's in a separate module. I can rebase when @TomAugspurger 's changes get in. Also started working on turning the |
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.
looks good
couple of comments - will let u know when to rebase
result = op(grouped)['C'] | ||
if name in ['sum', 'prod']: | ||
tm.assert_series_equal(result, exp) | ||
|
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.
yes u can collapse testit - just move everything up
expected = df.groupby(labels).agg(targop) | ||
try: | ||
tm.assert_frame_equal(result, expected) | ||
except BaseException as exc: |
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.
yes u can take this try/except out
it’s helpful when not parametrized but not now
['C', grouped['C'].mean()], | ||
['D', grouped['D'].sem()]])) | ||
tm.assert_frame_equal(result, expected) | ||
|
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.
same - collapse this function
@alysivji if you want to rebase we can get this in. |
@jreback all green! Will start working on refactoring the setup method to fixtures this weekend. |
thanks @alysivji would like to remove the imports inside functions as well (and consolidate at the top-level) on your next PR. |
closes #18490
Module currently has tests in 2 classes (
TestGroupByAggregate
andTestGroupByAggregateCython
). The remaining tests are not in a class.Also made the following changes:
TestGroupByAggregate class
test_agg_must_agg
pytest.raises
withtm.assert_raises_regex
test_agg_apply_corner
test_agg_multiple_functions_too_many_lambdas
pytest.raises
withtm.assert_raises_regex
test_multi_function_flexible_mix
TestGroupByAggregateCython class
all test methods that contain cython in the test name
test_cython_agg_nothing_to_agg
pytest.raises
withtm.assert_raises_regex
test_cython_agg_return_dict
self.df
with df initialized inside functionAll Others
test_agg_dict_renaming_deprecation
test_agg_nested_dicts
pytest.raises
withtm.assert_raises_regex
test_agg_item_by_item_raise_typeerror
pytest.raises
withtm.assert_raises_regex
test_agg_structs_series