Skip to content

REF/TST: Add more pytest idiom to tests/resample #24230

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 12 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions pandas/tests/resample/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from datetime import datetime

import numpy as np
import pytest

from pandas.tests.resample.test_base import (
downsample_methods, resample_methods, upsample_methods)
from pandas import DataFrame, Series
from pandas.core.indexes.datetimes import date_range
from pandas.core.indexes.period import period_range

# The various methods we support
downsample_methods = ['min', 'max', 'first', 'last', 'sum', 'mean', 'sem',
'median', 'prod', 'var', 'std', 'ohlc', 'quantile']
upsample_methods = ['count', 'size']
series_methods = ['nunique']
resample_methods = downsample_methods + upsample_methods + series_methods


@pytest.fixture(params=downsample_methods)
Expand All @@ -20,3 +31,68 @@ def upsample_method(request):
def resample_method(request):
"""Fixture for parametrization of Grouper resample methods."""
return request.param


@pytest.fixture
def simple_date_range_series():
"""
Series with date range index and random data for test purposes.
"""
def _simple_date_range_series(start, end, freq='D'):
rng = date_range(start, end, freq=freq)
return Series(np.random.randn(len(rng)), index=rng)
return _simple_date_range_series


@pytest.fixture
def simple_period_range_series():
"""
Series with period range index and random data for test purposes.
"""
def _simple_period_range_series(start, end, freq='D'):
rng = period_range(start, end, freq=freq)
return Series(np.random.randn(len(rng)), index=rng)
return _simple_period_range_series


@pytest.fixture
def _index_start():
return datetime(2005, 1, 1)


@pytest.fixture
def _index_end():
return datetime(2005, 1, 10)


@pytest.fixture
def _index_freq():
return 'D'


@pytest.fixture
def index(_index_factory, _index_start, _index_end, _index_freq):
return _index_factory(_index_start, _index_end, freq=_index_freq)


@pytest.fixture
def _static_values(index):
return np.arange(len(index))


@pytest.fixture
def series(index, _series_name, _static_values):
return Series(_static_values, index=index, name=_series_name)


@pytest.fixture
def frame(index, _static_values):
return DataFrame({'value': _static_values}, index=index)


@pytest.fixture(params=[Series, DataFrame])
def series_and_frame(request, series, frame):
if request.param == Series:
return series
if request.param == DataFrame:
return frame
Loading