Skip to content
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

TST: organize and cleanup pandas/tests/groupby/test_aggregate.py #18931

Merged
merged 13 commits into from
Dec 30, 2017

Conversation

alysivji
Copy link
Contributor

closes #18490

Module currently has tests in 2 classes (TestGroupByAggregate and TestGroupByAggregateCython). The remaining tests are not in a class.

Also made the following changes:

TestGroupByAggregate class

test_agg_must_agg

  • replaced pytest.raises with tm.assert_raises_regex

test_agg_apply_corner

  • made it more readable

test_agg_multiple_functions_too_many_lambdas

  • replaced pytest.raises with tm.assert_raises_regex

test_multi_function_flexible_mix

  • made it more readable

TestGroupByAggregateCython class

all test methods that contain cython in the test name

test_cython_agg_nothing_to_agg

  • replaced pytest.raises with tm.assert_raises_regex

test_cython_agg_return_dict

  • replaced self.df with df initialized inside function

All Others

test_agg_dict_renaming_deprecation

  • made it more readable

test_agg_nested_dicts

  • replaced pytest.raises with tm.assert_raises_regex
  • made it more readable

test_agg_item_by_item_raise_typeerror

  • replaced pytest.raises with tm.assert_raises_regex

test_agg_structs_series

  • made it more readable

@codecov
Copy link

codecov bot commented Dec 24, 2017

Codecov Report

Merging #18931 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.94% <ø> (-0.01%) ⬇️
#single 41.72% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/util/testing.py 84.74% <0%> (-0.22%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8433562...5d763ff. Read the comment docs.

@sinhrks sinhrks added Clean Testing pandas testing functions or related to the test suite labels Dec 25, 2017
@jreback
Copy link
Contributor

jreback commented Dec 26, 2017

thanks @alysivji

can you split things out to new files?

IOW each of these classes to a separate file, something like

pandas/tests/groupby/aggregate/test_cython (2nd one)
test_aggregate (1st class)
test_other (3rd one)

just to make this even more organized.

be sure to add a __init__.py in the sub-dir

@alysivji alysivji force-pushed the issue_18490 branch 2 times, most recently from 02ebbf0 to dfd192e Compare December 27, 2017 17:29
@alysivji
Copy link
Contributor Author

  • Split up the files
  • cleaned up the imports
  • changed all assert_frame/assert_series calls to tm.assert_*
  • more cleaning up tests to increase readability
  • rebased

@jreback lemme know if anything else needs to be done.

Thanks!

Copy link
Contributor

@jreback jreback left a 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):
Copy link
Contributor

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
Copy link
Contributor

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):
Copy link
Contributor

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),
Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@jreback
Copy link
Contributor

jreback commented Dec 27, 2017

cc @TomAugspurger I think we have to merge #18921 (when ready) before this (and rebase this on master)?

@TomAugspurger
Copy link
Contributor

Yes it'd be nice to merge #18921 before this. Backporting can be tricky when files are split.

@jreback
Copy link
Contributor

jreback commented Dec 27, 2017

@alysivji but go ahead and make the changes as above when you can. we will be merging @TomAugspurger soon anyhow.

@alysivji
Copy link
Contributor Author

@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 test_aggregate.py setup into fixtures. Lots of moving pieces for one PR; will send a separate request once this is merged.

Copy link
Contributor

@jreback jreback left a 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)

Copy link
Contributor

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:
Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

same - collapse this function

@jreback
Copy link
Contributor

jreback commented Dec 29, 2017

@alysivji if you want to rebase we can get this in.

@alysivji
Copy link
Contributor Author

@jreback all green!

Will start working on refactoring the setup method to fixtures this weekend.

@jreback jreback added this to the 0.23.0 milestone Dec 30, 2017
@jreback jreback merged commit faeac49 into pandas-dev:master Dec 30, 2017
@jreback
Copy link
Contributor

jreback commented Dec 30, 2017

thanks @alysivji

would like to remove the imports inside functions as well (and consolidate at the top-level) on your next PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: organize pandas/tests/groupby/test_aggregate.py
4 participants