Skip to content

Commit f1f6f02

Browse files
winklerandjreback
authored andcommitted
TST: convert constant 'setup-like' values/objects to pytest fixtures
1 parent 1fb6ff6 commit f1f6f02

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
@@ -18,7 +18,7 @@
1818

1919
from pandas.core.dtypes.generic import ABCSeries, ABCDataFrame
2020
from pandas.compat import range, lrange, zip, product, OrderedDict
21-
from pandas.core.base import SpecificationError
21+
from pandas.core.base import SpecificationError, AbstractMethodError
2222
from pandas.errors import UnsupportedFunctionCall
2323
from pandas.core.groupby import DataError
2424
from pandas.tseries.frequencies import MONTHS, DAYS
@@ -698,32 +698,44 @@ def create_index(self, *args, **kwargs):
698698
factory = self._index_factory()
699699
return factory(*args, **kwargs)
700700

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

705713
@pytest.fixture
706-
def index(self):
707-
return self.create_index(self._index_fixture_start,
708-
self._index_fixture_end,
709-
freq=self._index_fixture_freq)
714+
def index(self, _index_start, _index_end, _index_freq):
715+
return self.create_index(_index_start, _index_end, freq=_index_freq)
710716

711717
@pytest.fixture
712-
def series(self, index):
713-
return Series(np.arange(len(index)), index=index,
714-
name=self._series_fixture_name)
718+
def _series_name(self):
719+
raise AbstractMethodError(self)
715720

716721
@pytest.fixture
717-
def frame(self, index):
718-
return DataFrame({'value': np.arange(len(index))}, index=index)
722+
def _static_values(self, index):
723+
return np.arange(len(index))
724+
725+
@pytest.fixture
726+
def series(self, index, _series_name, _static_values):
727+
return Series(_static_values, index=index, name=_series_name)
728+
729+
@pytest.fixture
730+
def frame(self, index, _static_values):
731+
return DataFrame({'value': _static_values}, index=index)
719732

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

728740
@pytest.mark.parametrize('freq', ['2D', '1H'])
729741
def test_asfreq(self, series_and_frame, freq):
@@ -876,7 +888,10 @@ def test_apply_to_empty_series(self):
876888

877889
class TestDatetimeIndex(Base):
878890
_index_factory = lambda x: date_range
879-
_series_fixture_name = 'dti'
891+
892+
@pytest.fixture
893+
def _series_name(self):
894+
return 'dti'
880895

881896
def setup_method(self, method):
882897
dti = DatetimeIndex(start=datetime(2005, 1, 1),
@@ -2225,7 +2240,10 @@ def test_resample_datetime_values(self):
22252240

22262241
class TestPeriodIndex(Base):
22272242
_index_factory = lambda x: period_range
2228-
_series_fixture_name = 'pi'
2243+
2244+
@pytest.fixture
2245+
def _series_name(self):
2246+
return 'pi'
22292247

22302248
def create_series(self):
22312249
# TODO: replace calls to .create_series() by injecting the series
@@ -2884,9 +2902,18 @@ def test_resample_with_only_nat(self):
28842902

28852903
class TestTimedeltaIndex(Base):
28862904
_index_factory = lambda x: timedelta_range
2887-
_series_fixture_name = 'tdi'
2888-
_index_fixture_start = '1 day'
2889-
_index_fixture_end = '10 day'
2905+
2906+
@pytest.fixture
2907+
def _index_start(self):
2908+
return '1 day'
2909+
2910+
@pytest.fixture
2911+
def _index_end(self):
2912+
return '10 day'
2913+
2914+
@pytest.fixture
2915+
def _series_name(self):
2916+
return 'tdi'
28902917

28912918
def create_series(self):
28922919
i = timedelta_range('1 day',

0 commit comments

Comments
 (0)