Skip to content

Commit 6ceba52

Browse files
authored
CLN: frequencies/test_inference.py (#44807)
1 parent 3397585 commit 6ceba52

File tree

1 file changed

+29
-71
lines changed

1 file changed

+29
-71
lines changed

pandas/tests/tseries/frequencies/test_inference.py

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,36 @@
2828
import pandas.tseries.offsets as offsets
2929

3030

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):
4458
freq = freq.upper()
4559

46-
gen = date_range(start, periods=periods, freq=freq)
60+
gen = date_range("1/1/2000", periods=periods, freq=freq)
4761
index = DatetimeIndex(gen.values)
4862

4963
if not freq.startswith("Q-"):
@@ -72,41 +86,6 @@ def _check_generated_range(start, periods, freq):
7286
assert is_dec_range or is_nov_range or is_oct_range
7387

7488

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-
11089
def test_raise_if_period_index():
11190
index = period_range(start="1/1/1990", periods=20, freq="M")
11291
msg = "Check the `freq` attribute instead of using infer_freq"
@@ -184,6 +163,7 @@ def test_annual_ambiguous():
184163
assert rng.inferred_freq == "A-JAN"
185164

186165

166+
@pytest.mark.parametrize("count", range(1, 5))
187167
def test_infer_freq_delta(base_delta_code_pair, count):
188168
b = Timestamp(datetime.now())
189169
base_delta, code = base_delta_code_pair
@@ -214,28 +194,6 @@ def test_infer_freq_custom(base_delta_code_pair, constructor):
214194
assert frequencies.infer_freq(index) is None
215195

216196

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-
239197
@pytest.mark.parametrize(
240198
"freq,expected", [("Q", "Q-DEC"), ("Q-NOV", "Q-NOV"), ("Q-OCT", "Q-OCT")]
241199
)

0 commit comments

Comments
 (0)