|
| 1 | +from datetime import ( |
| 2 | + datetime, |
| 3 | + timedelta, |
| 4 | +) |
| 5 | + |
| 6 | +import numpy as np |
| 7 | +import pytest |
| 8 | + |
| 9 | +import pandas.util._test_decorators as td |
| 10 | + |
| 11 | +from pandas import ( |
| 12 | + DataFrame, |
| 13 | + Series, |
| 14 | + bdate_range, |
| 15 | + to_datetime, |
| 16 | +) |
| 17 | + |
| 18 | + |
| 19 | +@pytest.fixture(params=[True, False]) |
| 20 | +def raw(request): |
| 21 | + """raw keyword argument for rolling.apply""" |
| 22 | + return request.param |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture( |
| 26 | + params=[ |
| 27 | + "triang", |
| 28 | + "blackman", |
| 29 | + "hamming", |
| 30 | + "bartlett", |
| 31 | + "bohman", |
| 32 | + "blackmanharris", |
| 33 | + "nuttall", |
| 34 | + "barthann", |
| 35 | + ] |
| 36 | +) |
| 37 | +def win_types(request): |
| 38 | + return request.param |
| 39 | + |
| 40 | + |
| 41 | +@pytest.fixture(params=["kaiser", "gaussian", "general_gaussian", "exponential"]) |
| 42 | +def win_types_special(request): |
| 43 | + return request.param |
| 44 | + |
| 45 | + |
| 46 | +@pytest.fixture( |
| 47 | + params=[ |
| 48 | + "sum", |
| 49 | + "mean", |
| 50 | + "median", |
| 51 | + "max", |
| 52 | + "min", |
| 53 | + "var", |
| 54 | + "std", |
| 55 | + "kurt", |
| 56 | + "skew", |
| 57 | + "count", |
| 58 | + "sem", |
| 59 | + ] |
| 60 | +) |
| 61 | +def arithmetic_win_operators(request): |
| 62 | + return request.param |
| 63 | + |
| 64 | + |
| 65 | +@pytest.fixture( |
| 66 | + params=[ |
| 67 | + ["sum", {}], |
| 68 | + ["mean", {}], |
| 69 | + ["median", {}], |
| 70 | + ["max", {}], |
| 71 | + ["min", {}], |
| 72 | + ["var", {}], |
| 73 | + ["var", {"ddof": 0}], |
| 74 | + ["std", {}], |
| 75 | + ["std", {"ddof": 0}], |
| 76 | + ] |
| 77 | +) |
| 78 | +def arithmetic_numba_supported_operators(request): |
| 79 | + return request.param |
| 80 | + |
| 81 | + |
| 82 | +@pytest.fixture(params=["right", "left", "both", "neither"]) |
| 83 | +def closed(request): |
| 84 | + return request.param |
| 85 | + |
| 86 | + |
| 87 | +@pytest.fixture(params=[True, False]) |
| 88 | +def center(request): |
| 89 | + return request.param |
| 90 | + |
| 91 | + |
| 92 | +@pytest.fixture(params=[None, 1]) |
| 93 | +def min_periods(request): |
| 94 | + return request.param |
| 95 | + |
| 96 | + |
| 97 | +@pytest.fixture(params=["single", "table"]) |
| 98 | +def method(request): |
| 99 | + """method keyword in rolling/expanding/ewm constructor""" |
| 100 | + return request.param |
| 101 | + |
| 102 | + |
| 103 | +@pytest.fixture(params=[True, False]) |
| 104 | +def parallel(request): |
| 105 | + """parallel keyword argument for numba.jit""" |
| 106 | + return request.param |
| 107 | + |
| 108 | + |
| 109 | +# Can parameterize nogil & nopython over True | False, but limiting per |
| 110 | +# https://github.com/pandas-dev/pandas/pull/41971#issuecomment-860607472 |
| 111 | + |
| 112 | + |
| 113 | +@pytest.fixture(params=[False]) |
| 114 | +def nogil(request): |
| 115 | + """nogil keyword argument for numba.jit""" |
| 116 | + return request.param |
| 117 | + |
| 118 | + |
| 119 | +@pytest.fixture(params=[True]) |
| 120 | +def nopython(request): |
| 121 | + """nopython keyword argument for numba.jit""" |
| 122 | + return request.param |
| 123 | + |
| 124 | + |
| 125 | +@pytest.fixture(params=[True, False]) |
| 126 | +def adjust(request): |
| 127 | + """adjust keyword argument for ewm""" |
| 128 | + return request.param |
| 129 | + |
| 130 | + |
| 131 | +@pytest.fixture(params=[True, False]) |
| 132 | +def ignore_na(request): |
| 133 | + """ignore_na keyword argument for ewm""" |
| 134 | + return request.param |
| 135 | + |
| 136 | + |
| 137 | +@pytest.fixture(params=[pytest.param("numba", marks=td.skip_if_no("numba")), "cython"]) |
| 138 | +def engine(request): |
| 139 | + """engine keyword argument for rolling.apply""" |
| 140 | + return request.param |
| 141 | + |
| 142 | + |
| 143 | +@pytest.fixture( |
| 144 | + params=[ |
| 145 | + pytest.param(("numba", True), marks=td.skip_if_no("numba")), |
| 146 | + ("cython", True), |
| 147 | + ("cython", False), |
| 148 | + ] |
| 149 | +) |
| 150 | +def engine_and_raw(request): |
| 151 | + """engine and raw keyword arguments for rolling.apply""" |
| 152 | + return request.param |
| 153 | + |
| 154 | + |
| 155 | +@pytest.fixture |
| 156 | +def times_frame(): |
| 157 | + """Frame for testing times argument in EWM groupby.""" |
| 158 | + return DataFrame( |
| 159 | + { |
| 160 | + "A": ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"], |
| 161 | + "B": [0, 0, 0, 1, 1, 1, 2, 2, 2, 3], |
| 162 | + "C": to_datetime( |
| 163 | + [ |
| 164 | + "2020-01-01", |
| 165 | + "2020-01-01", |
| 166 | + "2020-01-01", |
| 167 | + "2020-01-02", |
| 168 | + "2020-01-10", |
| 169 | + "2020-01-22", |
| 170 | + "2020-01-03", |
| 171 | + "2020-01-23", |
| 172 | + "2020-01-23", |
| 173 | + "2020-01-04", |
| 174 | + ] |
| 175 | + ), |
| 176 | + } |
| 177 | + ) |
| 178 | + |
| 179 | + |
| 180 | +@pytest.fixture(params=["1 day", timedelta(days=1)]) |
| 181 | +def halflife_with_times(request): |
| 182 | + """Halflife argument for EWM when times is specified.""" |
| 183 | + return request.param |
| 184 | + |
| 185 | + |
| 186 | +@pytest.fixture( |
| 187 | + params=[ |
| 188 | + "object", |
| 189 | + "category", |
| 190 | + "int8", |
| 191 | + "int16", |
| 192 | + "int32", |
| 193 | + "int64", |
| 194 | + "uint8", |
| 195 | + "uint16", |
| 196 | + "uint32", |
| 197 | + "uint64", |
| 198 | + "float16", |
| 199 | + "float32", |
| 200 | + "float64", |
| 201 | + "m8[ns]", |
| 202 | + "M8[ns]", |
| 203 | + "datetime64[ns, UTC]", |
| 204 | + ] |
| 205 | +) |
| 206 | +def dtypes(request): |
| 207 | + """Dtypes for window tests""" |
| 208 | + return request.param |
| 209 | + |
| 210 | + |
| 211 | +@pytest.fixture( |
| 212 | + params=[ |
| 213 | + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 0]), |
| 214 | + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1, 1]), |
| 215 | + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", "C"]), |
| 216 | + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[1.0, 0]), |
| 217 | + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0.0, 1]), |
| 218 | + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=["C", 1]), |
| 219 | + DataFrame([[2.0, 4.0], [1.0, 2.0], [5.0, 2.0], [8.0, 1.0]], columns=[1, 0.0]), |
| 220 | + DataFrame([[2, 4.0], [1, 2.0], [5, 2.0], [8, 1.0]], columns=[0, 1.0]), |
| 221 | + DataFrame([[2, 4], [1, 2], [5, 2], [8, 1.0]], columns=[1.0, "X"]), |
| 222 | + ] |
| 223 | +) |
| 224 | +def pairwise_frames(request): |
| 225 | + """Pairwise frames test_pairwise""" |
| 226 | + return request.param |
| 227 | + |
| 228 | + |
| 229 | +@pytest.fixture |
| 230 | +def pairwise_target_frame(): |
| 231 | + """Pairwise target frame for test_pairwise""" |
| 232 | + return DataFrame([[2, 4], [1, 2], [5, 2], [8, 1]], columns=[0, 1]) |
| 233 | + |
| 234 | + |
| 235 | +@pytest.fixture |
| 236 | +def pairwise_other_frame(): |
| 237 | + """Pairwise other frame for test_pairwise""" |
| 238 | + return DataFrame( |
| 239 | + [[None, 1, 1], [None, 1, 2], [None, 3, 2], [None, 8, 1]], |
| 240 | + columns=["Y", "Z", "X"], |
| 241 | + ) |
| 242 | + |
| 243 | + |
| 244 | +@pytest.fixture |
| 245 | +def series(): |
| 246 | + """Make mocked series as fixture.""" |
| 247 | + arr = np.random.randn(100) |
| 248 | + locs = np.arange(20, 40) |
| 249 | + arr[locs] = np.NaN |
| 250 | + series = Series(arr, index=bdate_range(datetime(2009, 1, 1), periods=100)) |
| 251 | + return series |
| 252 | + |
| 253 | + |
| 254 | +@pytest.fixture |
| 255 | +def frame(): |
| 256 | + """Make mocked frame as fixture.""" |
| 257 | + return DataFrame( |
| 258 | + np.random.randn(100, 10), |
| 259 | + index=bdate_range(datetime(2009, 1, 1), periods=100), |
| 260 | + columns=np.arange(10), |
| 261 | + ) |
0 commit comments