|
28 | 28 | import pandas.tseries.offsets as offsets
|
29 | 29 |
|
30 | 30 |
|
31 |
| -def _check_generated_range(start, periods, freq): |
32 |
| - """ |
33 |
| - Check the range generated from a given start, frequency, and period count. |
34 |
| -
|
35 |
| - Parameters |
36 |
| - ---------- |
37 |
| - start : str |
38 |
| - The start date. |
39 |
| - periods : int |
40 |
| - The number of periods. |
41 |
| - freq : str |
42 |
| - The frequency of the range. |
43 |
| - """ |
| 31 | +@pytest.fixture( |
| 32 | + params=[ |
| 33 | + (timedelta(1), "D"), |
| 34 | + (timedelta(hours=1), "H"), |
| 35 | + (timedelta(minutes=1), "T"), |
| 36 | + (timedelta(seconds=1), "S"), |
| 37 | + (np.timedelta64(1, "ns"), "N"), |
| 38 | + (timedelta(microseconds=1), "U"), |
| 39 | + (timedelta(microseconds=1000), "L"), |
| 40 | + ] |
| 41 | +) |
| 42 | +def base_delta_code_pair(request): |
| 43 | + return request.param |
| 44 | + |
| 45 | + |
| 46 | +freqs = ( |
| 47 | + [f"Q-{month}" for month in MONTHS] |
| 48 | + + [f"{annual}-{month}" for annual in ["A", "BA"] for month in MONTHS] |
| 49 | + + ["M", "BM", "BMS"] |
| 50 | + + [f"WOM-{count}{day}" for count in range(1, 5) for day in DAYS] |
| 51 | + + [f"W-{day}" for day in DAYS] |
| 52 | +) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.parametrize("freq", freqs) |
| 56 | +@pytest.mark.parametrize("periods", [5, 7]) |
| 57 | +def test_infer_freq_range(periods, freq): |
44 | 58 | freq = freq.upper()
|
45 | 59 |
|
46 |
| - gen = date_range(start, periods=periods, freq=freq) |
| 60 | + gen = date_range("1/1/2000", periods=periods, freq=freq) |
47 | 61 | index = DatetimeIndex(gen.values)
|
48 | 62 |
|
49 | 63 | if not freq.startswith("Q-"):
|
@@ -72,41 +86,6 @@ def _check_generated_range(start, periods, freq):
|
72 | 86 | assert is_dec_range or is_nov_range or is_oct_range
|
73 | 87 |
|
74 | 88 |
|
75 |
| -@pytest.fixture( |
76 |
| - params=[ |
77 |
| - (timedelta(1), "D"), |
78 |
| - (timedelta(hours=1), "H"), |
79 |
| - (timedelta(minutes=1), "T"), |
80 |
| - (timedelta(seconds=1), "S"), |
81 |
| - (np.timedelta64(1, "ns"), "N"), |
82 |
| - (timedelta(microseconds=1), "U"), |
83 |
| - (timedelta(microseconds=1000), "L"), |
84 |
| - ] |
85 |
| -) |
86 |
| -def base_delta_code_pair(request): |
87 |
| - return request.param |
88 |
| - |
89 |
| - |
90 |
| -@pytest.fixture(params=[1, 2, 3, 4]) |
91 |
| -def count(request): |
92 |
| - return request.param |
93 |
| - |
94 |
| - |
95 |
| -@pytest.fixture(params=DAYS) |
96 |
| -def day(request): |
97 |
| - return request.param |
98 |
| - |
99 |
| - |
100 |
| -@pytest.fixture(params=MONTHS) |
101 |
| -def month(request): |
102 |
| - return request.param |
103 |
| - |
104 |
| - |
105 |
| -@pytest.fixture(params=[5, 7]) |
106 |
| -def periods(request): |
107 |
| - return request.param |
108 |
| - |
109 |
| - |
110 | 89 | def test_raise_if_period_index():
|
111 | 90 | index = period_range(start="1/1/1990", periods=20, freq="M")
|
112 | 91 | msg = "Check the `freq` attribute instead of using infer_freq"
|
@@ -184,6 +163,7 @@ def test_annual_ambiguous():
|
184 | 163 | assert rng.inferred_freq == "A-JAN"
|
185 | 164 |
|
186 | 165 |
|
| 166 | +@pytest.mark.parametrize("count", range(1, 5)) |
187 | 167 | def test_infer_freq_delta(base_delta_code_pair, count):
|
188 | 168 | b = Timestamp(datetime.now())
|
189 | 169 | base_delta, code = base_delta_code_pair
|
@@ -214,28 +194,6 @@ def test_infer_freq_custom(base_delta_code_pair, constructor):
|
214 | 194 | assert frequencies.infer_freq(index) is None
|
215 | 195 |
|
216 | 196 |
|
217 |
| -def test_weekly_infer(periods, day): |
218 |
| - _check_generated_range("1/1/2000", periods, f"W-{day}") |
219 |
| - |
220 |
| - |
221 |
| -def test_week_of_month_infer(periods, day, count): |
222 |
| - _check_generated_range("1/1/2000", periods, f"WOM-{count}{day}") |
223 |
| - |
224 |
| - |
225 |
| -@pytest.mark.parametrize("freq", ["M", "BM", "BMS"]) |
226 |
| -def test_monthly_infer(periods, freq): |
227 |
| - _check_generated_range("1/1/2000", periods, "M") |
228 |
| - |
229 |
| - |
230 |
| -def test_quarterly_infer(month, periods): |
231 |
| - _check_generated_range("1/1/2000", periods, f"Q-{month}") |
232 |
| - |
233 |
| - |
234 |
| -@pytest.mark.parametrize("annual", ["A", "BA"]) |
235 |
| -def test_annually_infer(month, periods, annual): |
236 |
| - _check_generated_range("1/1/2000", periods, f"{annual}-{month}") |
237 |
| - |
238 |
| - |
239 | 197 | @pytest.mark.parametrize(
|
240 | 198 | "freq,expected", [("Q", "Q-DEC"), ("Q-NOV", "Q-NOV"), ("Q-OCT", "Q-OCT")]
|
241 | 199 | )
|
|
0 commit comments