Skip to content

CLN: refactor tests in test_moments_ewm.py #30570

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 8 commits into from
Jan 3, 2020

Conversation

charlesdong1991
Copy link
Member

@jreback jreback added Testing pandas testing functions or related to the test suite Window rolling, ewma, expanding labels Jan 1, 2020
@@ -263,49 +265,68 @@ class TestEwmMomentsConsistency(ConsistencyBase):
def setup_method(self, method):
self._create_data()

def test_ewmcov(self):
self._check_binary_ew("cov")
def _create_binary_ew_data(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

make this a fixture

Copy link
Member Author

Choose a reason for hiding this comment

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

made


def test_ewmcov_pairwise(self):
self._check_pairwise_moment("ewm", "cov", span=10, min_periods=5)

def test_ewmcorr(self):
self._check_binary_ew("corr")
@pytest.mark.parametrize("min_periods", [0, 1, 2])
Copy link
Contributor

Choose a reason for hiding this comment

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

you can just create a fixture with these min_periods (you can put in a conftest.py in this directory)

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, i made a conftest.py under moments directory, and add couple fixtures there


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

def _check_binary_ew(self, name):
def _check_binary_ew(self, name, A, B):
Copy link
Contributor

Choose a reason for hiding this comment

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

make this a free function, put in common.py

Copy link
Member Author

Choose a reason for hiding this comment

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

changed

result = func(A, B, 20, min_periods=5)
assert np.isnan(result.values[:14]).all()
assert not np.isnan(result.values[14:]).any()

def _check_binary_ew_min_periods(self, name, min_periods, A, B):
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Member Author

Choose a reason for hiding this comment

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

changed

Copy link
Contributor

Choose a reason for hiding this comment

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

this does not need to be on the class, it can just be a free function in common.py

also rename these to something like

check_binary_ew_min_periods (de-prevatize)

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, i fixed! and also combined two methods with parametrization since they are almost identical!

thanks!

@@ -348,3 +348,7 @@ def get_result(obj, obj2=None):
result.index = result.index.droplevel(1)
expected = get_result(self.frame[1], self.frame[5])
tm.assert_series_equal(result, expected, check_names=False)

@staticmethod
Copy link
Contributor

Choose a reason for hiding this comment

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

just make this a module level function, ideally we want to get rid of all of the class based stuff eventually here.

Copy link
Contributor

Choose a reason for hiding this comment

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

these also don't need to be private (leading underscore)

Copy link
Member Author

@charlesdong1991 charlesdong1991 Jan 3, 2020

Choose a reason for hiding this comment

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

just make this a module level function, ideally we want to get rid of all of the class based stuff eventually here.

ahh! I get what you meant before, sorry for misunderstanding! fixed!

result = func(A, B, 20, min_periods=5)
assert np.isnan(result.values[:14]).all()
assert not np.isnan(result.values[14:]).any()

def _check_binary_ew_min_periods(self, name, min_periods, A, B):
Copy link
Contributor

Choose a reason for hiding this comment

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

this does not need to be on the class, it can just be a free function in common.py

also rename these to something like

check_binary_ew_min_periods (de-prevatize)

@jreback jreback added this to the 1.0 milestone Jan 3, 2020
@jreback jreback merged commit ba742da into pandas-dev:master Jan 3, 2020
@jreback
Copy link
Contributor

jreback commented Jan 3, 2020

thanks @charlesdong1991
this scope is good. moving common functions out and simplifiying logic & parmeterizing. keep em coming here.

@charlesdong1991
Copy link
Member Author

thanks, will do @jreback

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.

3 participants