Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ca7b6f2
CLN: move PeriodIndex binning code to TimeGrouper
winklerand Apr 26, 2017
c27f430
TST/CLN: raise error when resampling with on= or level= selection
winklerand Apr 26, 2017
390e16e
BUG: resampling PeriodIndex now returns PeriodIndex (GH 12884, 15944)
winklerand Apr 26, 2017
23566c2
BUG: OHLC-upsampling of PeriodIndex now returns DataFrame (GH 13083)
winklerand Apr 26, 2017
a82879d
BUG: enable resampling with NaT in PeriodIndex (GH 13224)
winklerand Apr 26, 2017
4b1c740
CLN: remove warning on falling back to tstamp resampling with loffset
winklerand Apr 30, 2017
73c0990
CLN: use memb._isnan for NaT masking
winklerand May 1, 2017
fa6c1d3
DOC: added issue reference for OHLC resampling
winklerand May 1, 2017
7ea04e9
STYLE: added blank lines
winklerand May 1, 2017
82a8275
TST: convert to parametrized tests / pytest idiom
winklerand May 6, 2017
432c623
CLN/TST: call assert_almost_equal() when comparing Series/DataFrames
winklerand May 6, 2017
c8814fb
STYLE: added blank lines, removed odd whitespace, fixed typo
winklerand May 13, 2017
486ad67
TST: add test case for multiple consecutive NaTs in PeriodIndex
winklerand May 13, 2017
ad8519f
TST/DOC: added issue number to test case
winklerand May 13, 2017
39fc7e2
TST: consolidate test_asfreq_downsample, test_asfreq_upsample -> test…
winklerand May 13, 2017
efcad5b
TST: set fixtures to default function scoping
winklerand May 13, 2017
41401d4
TST: convert constant 'setup-like' values/objects to pytest fixtures
winklerand May 13, 2017
398a684
DOC: whatsnew v0.21.0 entry (in API changes section)
winklerand May 21, 2017
8358c41
fixups
jreback Sep 28, 2017
6084e0c
moar whatsnew
jreback Sep 29, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: convert constant 'setup-like' values/objects to pytest fixtures
  • Loading branch information
winklerand authored and jreback committed Sep 29, 2017
commit 41401d4637ff9fd5bf8650b8ce1c4ed5eabf956e
71 changes: 49 additions & 22 deletions pandas/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from pandas.core.dtypes.generic import ABCSeries, ABCDataFrame
from pandas.compat import range, lrange, zip, product, OrderedDict
from pandas.core.base import SpecificationError
from pandas.core.base import SpecificationError, AbstractMethodError
from pandas.errors import UnsupportedFunctionCall
from pandas.core.groupby import DataError
from pandas.tseries.frequencies import MONTHS, DAYS
Expand Down Expand Up @@ -698,32 +698,44 @@ def create_index(self, *args, **kwargs):
factory = self._index_factory()
return factory(*args, **kwargs)

_index_fixture_start = datetime(2005, 1, 1)
_index_fixture_end = datetime(2005, 1, 10)
_index_fixture_freq = 'D'
@pytest.fixture
def _index_start(self):
return datetime(2005, 1, 1)

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

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

@pytest.fixture
def index(self):
return self.create_index(self._index_fixture_start,
self._index_fixture_end,
freq=self._index_fixture_freq)
def index(self, _index_start, _index_end, _index_freq):
return self.create_index(_index_start, _index_end, freq=_index_freq)

@pytest.fixture
def series(self, index):
return Series(np.arange(len(index)), index=index,
name=self._series_fixture_name)
def _series_name(self):
raise AbstractMethodError(self)

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

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

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

@pytest.fixture(params=[Series, DataFrame])
def series_and_frame(self, request, index):
def series_and_frame(self, request, index, _series_name, _static_values):
if request.param == Series:
return Series(np.arange(len(index)), index=index,
name=self._series_fixture_name)
return Series(_static_values, index=index, name=_series_name)
if request.param == DataFrame:
return DataFrame({'value': np.arange(len(index))}, index=index)
return DataFrame({'value': _static_values}, index=index)

@pytest.mark.parametrize('freq', ['2D', '1H'])
def test_asfreq(self, series_and_frame, freq):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback
I consolidated the test_asfreq_downsample() and test_asfreq_upsample() tests in the Base class as well (so we don't have to override them in TestPeriodIndex). PTAL if everything's still correct and covered as before.

Expand Down Expand Up @@ -876,7 +888,10 @@ def test_apply_to_empty_series(self):

class TestDatetimeIndex(Base):
_index_factory = lambda x: date_range
_series_fixture_name = 'dti'

@pytest.fixture
def _series_name(self):
return 'dti'

def setup_method(self, method):
dti = DatetimeIndex(start=datetime(2005, 1, 1),
Expand Down Expand Up @@ -2225,7 +2240,10 @@ def test_resample_datetime_values(self):

class TestPeriodIndex(Base):
_index_factory = lambda x: period_range
_series_fixture_name = 'pi'

@pytest.fixture
def _series_name(self):
return 'pi'

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

class TestTimedeltaIndex(Base):
_index_factory = lambda x: timedelta_range
_series_fixture_name = 'tdi'
_index_fixture_start = '1 day'
_index_fixture_end = '10 day'

@pytest.fixture
def _index_start(self):
return '1 day'

@pytest.fixture
def _index_end(self):
return '10 day'

@pytest.fixture
def _series_name(self):
return 'tdi'

def create_series(self):
i = timedelta_range('1 day',
Expand Down