1
+ from datetime import datetime
2
+
3
+ import numpy as np
1
4
import pytest
2
5
3
- from pandas.tests.resample.test_base import (
4
- downsample_methods, resample_methods, upsample_methods)
6
+ from pandas import DataFrame, Series
7
+ from pandas.core.indexes.datetimes import date_range
8
+ from pandas.core.indexes.period import period_range
9
+
10
+ # The various methods we support
11
+ downsample_methods = ['min', 'max', 'first', 'last', 'sum', 'mean', 'sem',
12
+ 'median', 'prod', 'var', 'std', 'ohlc', 'quantile']
13
+ upsample_methods = ['count', 'size']
14
+ series_methods = ['nunique']
15
+ resample_methods = downsample_methods + upsample_methods + series_methods
5
16
6
17
7
18
@pytest.fixture(params=downsample_methods)
@@ -20,3 +31,68 @@ def upsample_method(request):
20
31
def resample_method(request):
21
32
"""Fixture for parametrization of Grouper resample methods."""
22
33
return request.param
34
+
35
+
36
+ @pytest.fixture
37
+ def simple_date_range_series():
38
+ """
39
+ Series with date range index and random data for test purposes.
40
+ """
41
+ def _simple_date_range_series(start, end, freq='D'):
42
+ rng = date_range(start, end, freq=freq)
43
+ return Series(np.random.randn(len(rng)), index=rng)
44
+ return _simple_date_range_series
45
+
46
+
47
+ @pytest.fixture
48
+ def simple_period_range_series():
49
+ """
50
+ Series with period range index and random data for test purposes.
51
+ """
52
+ def _simple_period_range_series(start, end, freq='D'):
53
+ rng = period_range(start, end, freq=freq)
54
+ return Series(np.random.randn(len(rng)), index=rng)
55
+ return _simple_period_range_series
56
+
57
+
58
+ @pytest.fixture
59
+ def _index_start():
60
+ return datetime(2005, 1, 1)
61
+
62
+
63
+ @pytest.fixture
64
+ def _index_end():
65
+ return datetime(2005, 1, 10)
66
+
67
+
68
+ @pytest.fixture
69
+ def _index_freq():
70
+ return 'D'
71
+
72
+
73
+ @pytest.fixture
74
+ def index(_index_factory, _index_start, _index_end, _index_freq):
75
+ return _index_factory(_index_start, _index_end, freq=_index_freq)
76
+
77
+
78
+ @pytest.fixture
79
+ def _static_values(index):
80
+ return np.arange(len(index))
81
+
82
+
83
+ @pytest.fixture
84
+ def series(index, _series_name, _static_values):
85
+ return Series(_static_values, index=index, name=_series_name)
86
+
87
+
88
+ @pytest.fixture
89
+ def frame(index, _static_values):
90
+ return DataFrame({'value': _static_values}, index=index)
91
+
92
+
93
+ @pytest.fixture(params=[Series, DataFrame])
94
+ def series_and_frame(request, series, frame):
95
+ if request.param == Series:
96
+ return series
97
+ if request.param == DataFrame:
98
+ return frame
0 commit comments