Skip to content

CLN: Use more pytest idioms in test_momemts_ewm.py #36801

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 2 commits into from
Oct 2, 2020

Conversation

mroeschke
Copy link
Member

  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

Use pytest.mark.parameterize and unnest helper test functions

@mroeschke mroeschke added Clean Testing pandas testing functions or related to the test suite Window rolling, ewma, expanding labels Oct 2, 2020
@mroeschke mroeschke added this to the 1.2 milestone Oct 2, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @mroeschke. A suggestion for an alternative approach that may not be any clearer, so feel free to ignore.

assert isinstance(series_result, Series)

frame_result = getattr(frame.ewm(com=10), name)()
frame_result = frame.ewm(com=10).mean()
Copy link
Member

Choose a reason for hiding this comment

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

rather than a test use two fixtures independently, could have a test_ewma_series and test_ewma_frame



@pytest.mark.parametrize("name", ["var", "vol"])
def test_ewmvar_ewmvol(series, frame, nan_locs, name):
check_ew(name=name, frame=frame, series=series, nan_locs=nan_locs)
def test_ewmvar_ewmvol(series, frame, name):
Copy link
Member

Choose a reason for hiding this comment

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

can this be combined with test_ewma

assert isinstance(series_result, Series)

frame_result = getattr(frame.ewm(com=10), name)()
assert type(frame_result) == DataFrame
Copy link
Member

Choose a reason for hiding this comment

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

why not isinstance?

(s1, False, False, [(1.0 - alpha) ** 2, np.nan, alpha]),
(s1, False, True, [(1.0 - alpha), np.nan, alpha]),
(s2, True, False, [np.nan, (1.0 - alpha) ** 3, np.nan, np.nan, 1.0, np.nan]),
(s2, True, True, [np.nan, (1.0 - alpha), np.nan, np.nan, 1.0, np.nan]),
Copy link
Member

@simonjayhawkins simonjayhawkins Oct 2, 2020

Choose a reason for hiding this comment

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

i'm not sure that the parameterisation is clearer.

maybe parameterise s, adjust and ignore_na independently (maybe with fixtures) and create a w fixture with a dictionary lookup. i.e. pass s, adjust and ignore_na to w fixture

maybe use a class just for namespacing and use class level fixtures.

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'll consider doing this change in a follow up PR. The main motivation with this pass is to ensure that parameterized test failures are more easily visible within pytest

@jreback jreback merged commit 3db38fb into pandas-dev:master Oct 2, 2020
@jreback
Copy link
Contributor

jreback commented Oct 2, 2020

thanks @mroeschke follows welcome (per @simonjayhawkins comments)

@mroeschke mroeschke deleted the clean/moments_ewm branch October 2, 2020 20:27
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
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 Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants