-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
jreback
merged 12 commits into
pandas-dev:master
from
simonjayhawkins:resample-fixtures
Dec 13, 2018
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5b2a400
fixtures for simple date_range and period_range series
simonjayhawkins 872e724
remove business_day_offset import
simonjayhawkins f578e27
replace resample/downsample_methods import with fixture
simonjayhawkins 1484708
replace *_methods in test_base.py with fixture
simonjayhawkins 096f4c0
remove import of Base class for test_timedelta.py
simonjayhawkins 06220b0
remove import of Base class for test_datetime_index.py
simonjayhawkins 5df05a2
remove import of Base class for test_period_index.py
simonjayhawkins 5d42be2
move create_index fixture from conftest.py to module scope
simonjayhawkins 8ce8586
remove catching of BaseException
simonjayhawkins e29ffec
move ohlc to a separate test
simonjayhawkins abb909d
Merge remote-tracking branch 'upstream/master' into resample-fixtures
simonjayhawkins 693f84a
Merge remote-tracking branch 'upstream/master' into resample-fixtures
simonjayhawkins 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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,15 +18,13 @@ | |
from pandas.core.indexes.period import Period, period_range | ||
from pandas.core.indexes.timedeltas import timedelta_range | ||
from pandas.core.resample import DatetimeIndex, TimeGrouper | ||
from pandas.tests.resample.test_base import ( | ||
Base, business_day_offset, downsample_methods, simple_date_range_series, | ||
simple_period_range_series) | ||
from pandas.tests.resample.test_base import Base | ||
import pandas.util.testing as tm | ||
from pandas.util.testing import ( | ||
assert_almost_equal, assert_frame_equal, assert_series_equal) | ||
|
||
import pandas.tseries.offsets as offsets | ||
from pandas.tseries.offsets import Minute | ||
from pandas.tseries.offsets import BDay, Minute | ||
|
||
|
||
class TestDatetimeIndex(Base): | ||
|
@@ -131,7 +129,7 @@ def test_resample_string_kwargs(self): | |
with pytest.raises(ValueError): | ||
s.resample('5min', convention='starttt').mean() | ||
|
||
def test_resample_how(self): | ||
def test_resample_how(self, downsample_method): | ||
rng = date_range('1/1/2000 00:00:00', '1/1/2000 00:13:00', freq='min', | ||
name='index') | ||
s = Series(np.random.randn(14), index=rng) | ||
|
@@ -140,7 +138,7 @@ def test_resample_how(self): | |
grouplist[1:6] = 1 | ||
grouplist[6:11] = 2 | ||
grouplist[11:] = 3 | ||
args = downsample_methods | ||
arg = downsample_method | ||
|
||
def _ohlc(group): | ||
if isna(group).all(): | ||
|
@@ -149,29 +147,28 @@ def _ohlc(group): | |
|
||
inds = date_range('1/1/2000', periods=4, freq='5min', name='index') | ||
|
||
for arg in args: | ||
if arg == 'ohlc': | ||
func = _ohlc | ||
else: | ||
func = arg | ||
try: | ||
result = getattr(s.resample( | ||
'5min', closed='right', label='right'), arg)() | ||
|
||
expected = s.groupby(grouplist).agg(func) | ||
assert result.index.name == 'index' | ||
if arg == 'ohlc': | ||
func = _ohlc | ||
expected = DataFrame(expected.values.tolist()) | ||
expected.columns = ['open', 'high', 'low', 'close'] | ||
expected.index = Index(inds, name='index') | ||
assert_frame_equal(result, expected) | ||
else: | ||
func = arg | ||
try: | ||
result = getattr(s.resample( | ||
'5min', closed='right', label='right'), arg)() | ||
|
||
expected = s.groupby(grouplist).agg(func) | ||
assert result.index.name == 'index' | ||
if arg == 'ohlc': | ||
expected = DataFrame(expected.values.tolist()) | ||
expected.columns = ['open', 'high', 'low', 'close'] | ||
expected.index = Index(inds, name='index') | ||
assert_frame_equal(result, expected) | ||
else: | ||
expected.index = inds | ||
assert_series_equal(result, expected) | ||
except BaseException as exc: | ||
|
||
exc.args += ('how=%s' % arg,) | ||
raise | ||
expected.index = inds | ||
assert_series_equal(result, expected) | ||
except BaseException as exc: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remove this catching of BaseException (e.g. the try/accept), with parameterized methods it is uncessary |
||
|
||
exc.args += ('how=%s' % arg,) | ||
raise | ||
|
||
def test_numpy_compat(self): | ||
# see gh-12811 | ||
|
@@ -432,6 +429,7 @@ def test_resample_loffset(self, loffset): | |
|
||
# to weekly | ||
result = ser.resample('w-sun').last() | ||
business_day_offset = BDay() | ||
expected = ser.resample('w-sun', loffset=-business_day_offset).last() | ||
assert result.index[0] - business_day_offset == expected.index[0] | ||
|
||
|
@@ -628,7 +626,7 @@ def test_resample_reresample(self): | |
assert isinstance(result.index.freq, offsets.DateOffset) | ||
assert result.index.freq == offsets.Hour(8) | ||
|
||
def test_resample_timestamp_to_period(self): | ||
def test_resample_timestamp_to_period(self, simple_date_range_series): | ||
ts = simple_date_range_series('1/1/1990', '1/1/2000') | ||
|
||
result = ts.resample('A-DEC', kind='period').mean() | ||
|
@@ -945,7 +943,7 @@ def test_nanosecond_resample_error(self): | |
|
||
assert_series_equal(result, exp) | ||
|
||
def test_resample_anchored_intraday(self): | ||
def test_resample_anchored_intraday(self, simple_date_range_series): | ||
# #1471, #1458 | ||
|
||
rng = date_range('1/1/2012', '4/1/2012', freq='100min') | ||
|
@@ -985,7 +983,7 @@ def test_resample_anchored_intraday(self): | |
resampled = ts.resample('M').mean() | ||
assert len(resampled) == 1 | ||
|
||
def test_resample_anchored_monthstart(self): | ||
def test_resample_anchored_monthstart(self, simple_date_range_series): | ||
ts = simple_date_range_series('1/1/2000', '12/31/2002') | ||
|
||
freqs = ['MS', 'BMS', 'QS-MAR', 'AS-DEC', 'AS-JUN'] | ||
|
@@ -1015,7 +1013,8 @@ def test_resample_anchored_multiday(self): | |
result = s.resample('2200L', label='right').mean() | ||
assert result.index[-1] == Timestamp('2014-10-15 23:00:04.200') | ||
|
||
def test_corner_cases(self): | ||
def test_corner_cases(self, simple_period_range_series, | ||
simple_date_range_series): | ||
# miscellaneous test coverage | ||
|
||
rng = date_range('1/1/2000', periods=12, freq='t') | ||
|
@@ -1078,7 +1077,7 @@ def test_resample_median_bug_1688(self): | |
exp = df.asfreq('T') | ||
tm.assert_frame_equal(result, exp) | ||
|
||
def test_how_lambda_functions(self): | ||
def test_how_lambda_functions(self, simple_date_range_series): | ||
|
||
ts = simple_date_range_series('1/1/2000', '4/1/2000') | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be worthile to move ohlc to a separate test