Skip to content

Commit a16366a

Browse files
committed
TST: convert constant 'setup-like' values/objects to pytest fixtures
1 parent 6fe6c0c commit a16366a

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

pandas/tests/test_resample.py

+49-22
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from pandas.core.dtypes.generic import ABCSeries, ABCDataFrame
1717
from pandas.compat import range, lrange, zip, product, OrderedDict
18-
from pandas.core.base import SpecificationError
18+
from pandas.core.base import SpecificationError, AbstractMethodError
1919
from pandas.errors import UnsupportedFunctionCall
2020
from pandas.core.groupby import DataError
2121
from pandas.tseries.frequencies import MONTHS, DAYS
@@ -696,32 +696,44 @@ def create_index(self, *args, **kwargs):
696696
factory = self._index_factory()
697697
return factory(*args, **kwargs)
698698

699-
_index_fixture_start = datetime(2005, 1, 1)
700-
_index_fixture_end = datetime(2005, 1, 10)
701-
_index_fixture_freq = 'D'
699+
@pytest.fixture
700+
def _index_start(self):
701+
return datetime(2005, 1, 1)
702+
703+
@pytest.fixture
704+
def _index_end(self):
705+
return datetime(2005, 1, 10)
706+
707+
@pytest.fixture
708+
def _index_freq(self):
709+
return 'D'
702710

703711
@pytest.fixture
704-
def index(self):
705-
return self.create_index(self._index_fixture_start,
706-
self._index_fixture_end,
707-
freq=self._index_fixture_freq)
712+
def index(self, _index_start, _index_end, _index_freq):
713+
return self.create_index(_index_start, _index_end, freq=_index_freq)
708714

709715
@pytest.fixture
710-
def series(self, index):
711-
return Series(np.arange(len(index)), index=index,
712-
name=self._series_fixture_name)
716+
def _series_name(self):
717+
raise AbstractMethodError(self)
713718

714719
@pytest.fixture
715-
def frame(self, index):
716-
return DataFrame({'value': np.arange(len(index))}, index=index)
720+
def _static_values(self, index):
721+
return np.arange(len(index))
722+
723+
@pytest.fixture
724+
def series(self, index, _series_name, _static_values):
725+
return Series(_static_values, index=index, name=_series_name)
726+
727+
@pytest.fixture
728+
def frame(self, index, _static_values):
729+
return DataFrame({'value': _static_values}, index=index)
717730

718731
@pytest.fixture(params=[Series, DataFrame])
719-
def series_and_frame(self, request, index):
732+
def series_and_frame(self, request, index, _series_name, _static_values):
720733
if request.param == Series:
721-
return Series(np.arange(len(index)), index=index,
722-
name=self._series_fixture_name)
734+
return Series(_static_values, index=index, name=_series_name)
723735
if request.param == DataFrame:
724-
return DataFrame({'value': np.arange(len(index))}, index=index)
736+
return DataFrame({'value': _static_values}, index=index)
725737

726738
@pytest.mark.parametrize('freq', ['2D', '1H'])
727739
def test_asfreq(self, series_and_frame, freq):
@@ -860,7 +872,10 @@ def test_resample_loffset_arg_type(self):
860872

861873
class TestDatetimeIndex(Base):
862874
_index_factory = lambda x: date_range
863-
_series_fixture_name = 'dti'
875+
876+
@pytest.fixture
877+
def _series_name(self):
878+
return 'dti'
864879

865880
def setup_method(self, method):
866881
dti = DatetimeIndex(start=datetime(2005, 1, 1),
@@ -2179,7 +2194,10 @@ def test_resample_datetime_values(self):
21792194

21802195
class TestPeriodIndex(Base):
21812196
_index_factory = lambda x: period_range
2182-
_series_fixture_name = 'pi'
2197+
2198+
@pytest.fixture
2199+
def _series_name(self):
2200+
return 'pi'
21832201

21842202
def create_series(self):
21852203
# TODO: replace calls to .create_series() by injecting the series
@@ -2836,9 +2854,18 @@ def test_resample_with_only_nat(self):
28362854

28372855
class TestTimedeltaIndex(Base):
28382856
_index_factory = lambda x: timedelta_range
2839-
_series_fixture_name = 'tdi'
2840-
_index_fixture_start = '1 day'
2841-
_index_fixture_end = '10 day'
2857+
2858+
@pytest.fixture
2859+
def _index_start(self):
2860+
return '1 day'
2861+
2862+
@pytest.fixture
2863+
def _index_end(self):
2864+
return '10 day'
2865+
2866+
@pytest.fixture
2867+
def _series_name(self):
2868+
return 'tdi'
28422869

28432870
def create_series(self):
28442871
i = timedelta_range('1 day',

0 commit comments

Comments
 (0)