Skip to content

REF: Refactor window/test_moments.py #30542

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

Merged
merged 14 commits into from
Dec 30, 2019

Conversation

charlesdong1991
Copy link
Member

@charlesdong1991 charlesdong1991 commented Dec 29, 2019

@pep8speaks
Copy link

pep8speaks commented Dec 29, 2019

Hello @charlesdong1991! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-12-30 14:06:20 UTC

@simonjayhawkins simonjayhawkins added Testing pandas testing functions or related to the test suite Window rolling, ewma, expanding labels Dec 29, 2019
@charlesdong1991 charlesdong1991 marked this pull request as ready for review December 29, 2019 20:43

df2_result = f(df2)
tm.assert_frame_equal(df2_result, df2_expected)
except (ImportError):
Copy link
Member

Choose a reason for hiding this comment

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

Instead could you use a pytest.param(..., mark=pytest.mark.skipif(...) for the parameter that needs scipy.

Also, shouldn't all these parameters operate without scipy?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, they could operate without scipy. I removed.

expected = Series([1.0, 2.0, 3.0])
tm.assert_series_equal(result, expected)

def _check_expanding(
Copy link
Member

Choose a reason for hiding this comment

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

Could we break this into several different tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

i broke them into two

ser = Series([], dtype=np.float64)
tm.assert_series_equal(ser, ser.expanding().apply(lambda x: x.mean(), raw=raw))

# GH 8080
Copy link
Member

@mroeschke mroeschke Dec 30, 2019

Choose a reason for hiding this comment

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

This test looks like it could stand alone in its own function.

Copy link
Member Author

Choose a reason for hiding this comment

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

definitely!

# here to make this pass
self._check_expanding(expanding_mean, np.mean, preserve_nan=False)

ser = Series([], dtype=np.float64)
Copy link
Member

Choose a reason for hiding this comment

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

This test looks like it could stand alone in its own function.

Copy link
Member Author

Choose a reason for hiding this comment

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

sefinitely

def test_ewmcorr_pairwise(self):
self._check_pairwise_moment("ewm", "corr", span=10, min_periods=5)

def _check_binary_ew(self, name):
Copy link
Member

Choose a reason for hiding this comment

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

Could we break this into several different tests?

result = getattr(ewm, method)()
tm.assert_almost_equal(result, vals)

def _check_ew(self, name=None, preserve_nan=False):
Copy link
Member

Choose a reason for hiding this comment

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

Could we break this into several different tests?

super()._create_data()
self.data = _consistency_data

def _test_moments_consistency(
Copy link
Member

Choose a reason for hiding this comment

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

Could we break this into several different tests?

@jreback
Copy link
Contributor

jreback commented Dec 30, 2019

all of @mroeschke suggestions are good but i’d like to first just move things then actually break apart - otherwise the diffs are very hard to see

@charlesdong1991
Copy link
Member Author

@jreback thanks for your comments! Could you please explain a bit more about your point, i think currently this PR is basically simply moving things (except for a couple parametrizations). Or you want them to be split to different files/directories?

Would be nice to hear more so that I could make changes based on @mroeschke nice reviews later on tonight. Thanks!

@jreback
Copy link
Contributor

jreback commented Dec 30, 2019

i want things move with minimal changes in a PR
then you can come back with following PRs to actually parametize / split tests and so on
otherwise the diff is not clear in what is moving / what is actually changing

so pls make this PR solely about moving things to subdirectories (sure you will need some very minor changes to get things to pass) but don’t do anything more than that in this PR

@charlesdong1991
Copy link
Member Author

charlesdong1991 commented Dec 30, 2019

Hi, @jreback I revert the change based on your tips, and in this PR i only split tests into three sub-files

To be clear of what i did in this PR:
There is a subfolder now under window called moments, in which there are three files, for expanding, rolling and ewm separately. And in each file, there are two cases, one for TestMoments and one for TestMomentsConsistency.
In order to facilitate it, i made a base class for MomentsConsistency tests in common.py

@mroeschke many thanks for your nice reviews, following @jreback suggestion, I will address all of them in the follow-up PR and make this PR solely for tests split into sub-files.

@jreback jreback added this to the 1.0 milestone Dec 30, 2019
@jreback jreback merged commit 9c40e06 into pandas-dev:master Dec 30, 2019
@jreback
Copy link
Contributor

jreback commented Dec 30, 2019

thanks @charlesdong1991

yeah happy to have followups to split / clean this.

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

Successfully merging this pull request may close these issues.

5 participants