Skip to content

Commit 48e324f

Browse files
committed
TST: convert TestPeriodIndex.test_asfreq_upsample() to idiomatic pytest
1 parent 36a66d5 commit 48e324f

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

pandas/tests/test_resample.py

+33-23
Original file line numberDiff line numberDiff line change
@@ -2215,29 +2215,9 @@ def test_asfreq_downsample_kind_timestamp(self):
22152215
assert_frame_equal(result, expected)
22162216

22172217
def test_asfreq_upsample(self):
2218-
# GH 12884, 15944
2219-
2220-
s = self.create_series()
2221-
start = s.index[0].to_timestamp(how='start')
2222-
end = (s.index[-1] + 1).to_timestamp(how='start')
2223-
for freq in ['1H', '2H']:
2224-
# check base frequency and frequency multiple
2225-
new_index = date_range(start=start, end=end, freq=freq,
2226-
closed='left')
2227-
# series
2228-
expected = s.to_timestamp().reindex(new_index).to_period(freq)
2229-
result = s.resample(freq).asfreq()
2230-
assert_series_equal(result, expected)
2231-
result_kind_period = s.resample(freq, kind='period').asfreq()
2232-
assert_series_equal(result_kind_period, expected)
2233-
2234-
# frame
2235-
frame = s.to_frame('value')
2236-
expected = frame.to_timestamp().reindex(new_index).to_period(freq)
2237-
result = frame.resample(freq).asfreq()
2238-
assert_frame_equal(result, expected)
2239-
result_kind_period = frame.resample(freq, kind='period').asfreq()
2240-
assert_frame_equal(result_kind_period, expected)
2218+
# moved to TestPeriodIndexIdiomaticPytest, keep this as a dummy to
2219+
# override Base.test_asfreq_upsample()
2220+
pass
22412221

22422222
def test_asfreq_upsample_kind_timestamp(self):
22432223
s = self.create_series()
@@ -2910,6 +2890,36 @@ def test_resample_with_nat(self):
29102890
assert_frame_equal(result, expected)
29112891

29122892

2893+
def assert_series_or_frame_equal(result, expected):
2894+
if isinstance(result, Series):
2895+
return assert_series_equal(result, expected)
2896+
else:
2897+
return assert_frame_equal(result, expected)
2898+
2899+
2900+
class TestPeriodIndexIdiomaticPytest:
2901+
2902+
@pytest.fixture(params=[Series, DataFrame])
2903+
def pandas_obj(self, request):
2904+
i = period_range(datetime(2005, 1, 1),
2905+
datetime(2005, 1, 10), freq='D')
2906+
return request.param(np.arange(len(i)), index=i)
2907+
2908+
@pytest.mark.parametrize('freq', ['1H', '2H'])
2909+
@pytest.mark.parametrize('kind', ['period', None])
2910+
def test_asfreq_upsample(self, pandas_obj, freq, kind):
2911+
# GH 12884, 15944
2912+
2913+
obj = pandas_obj
2914+
start = obj.index[0].to_timestamp(how='start')
2915+
end = (obj.index[-1] + 1).to_timestamp(how='start')
2916+
new_index = date_range(start=start, end=end,
2917+
freq=freq, closed='left')
2918+
expected = obj.to_timestamp().reindex(new_index).to_period(freq)
2919+
result = obj.resample(freq, kind=kind).asfreq()
2920+
assert_series_or_frame_equal(result, expected)
2921+
2922+
29132923
class TestTimedeltaIndex(Base, tm.TestCase):
29142924
_index_factory = lambda x: timedelta_range
29152925

0 commit comments

Comments
 (0)