Skip to content

Commit e16a045

Browse files
committed
fix tests
1 parent aa7fa2b commit e16a045

File tree

6 files changed

+50
-31
lines changed

6 files changed

+50
-31
lines changed

pandas/tests/arrays/test_datetimes.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,8 @@ def test_iter_zoneinfo_fold(self, tz):
772772
("2QE-SEP", "2Q-SEP"),
773773
("1YE", "1Y"),
774774
("2YE-MAR", "2Y-MAR"),
775-
("1YE", "1A"),
776-
("2YE-MAR", "2A-MAR"),
777775
("2ME", "2m"),
778776
("2QE-SEP", "2q-sep"),
779-
("2YE-MAR", "2a-mar"),
780777
("2YE", "2y"),
781778
],
782779
)
@@ -826,6 +823,13 @@ def test_date_range_lowercase_frequency_deprecated(self, freq_depr):
826823
result = pd.date_range("1/1/2000", periods=4, freq=freq_depr)
827824
tm.assert_index_equal(result, expected)
828825

826+
@pytest.mark.parametrize("freq", ["1A", "2A-MAR", "2a-mar"])
827+
def test_date_range_frequency_A_raises(self, freq):
828+
msg = f"Invalid frequency: {freq}"
829+
830+
with pytest.raises(ValueError, match=msg):
831+
pd.date_range("1/1/2000", periods=4, freq=freq)
832+
829833

830834
def test_factorize_sort_without_freq():
831835
dta = DatetimeArray._from_sequence([0, 2, 1], dtype="M8[ns]")

pandas/tests/frame/methods/test_asfreq.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ def test_asfreq_2ME(self, freq, freq_half):
242242
("2BQE-SEP", "2BQ-SEP"),
243243
("1YE", "1Y"),
244244
("2YE-MAR", "2Y-MAR"),
245-
("1YE", "1A"),
246-
("2YE-MAR", "2A-MAR"),
247245
("2BYE-MAR", "2BA-MAR"),
248246
],
249247
)
@@ -283,3 +281,19 @@ def test_asfreq_unsupported_freq(self, freq, error_msg):
283281

284282
with pytest.raises(ValueError, match=error_msg):
285283
df.asfreq(freq=freq)
284+
285+
@pytest.mark.parametrize(
286+
"freq, freq_depr",
287+
[
288+
("1YE", "1A"),
289+
("2YE-MAR", "2A-MAR"),
290+
],
291+
)
292+
def test_asfreq_frequency_A_raisees(self, freq, freq_depr):
293+
msg = f"Invalid frequency: {freq_depr[1:]}"
294+
295+
index = date_range("1/1/2000", periods=4, freq=f"{freq[1:]}")
296+
df = DataFrame({"s": Series([0.0, 1.0, 2.0, 3.0], index=index)})
297+
298+
with pytest.raises(ValueError, match=msg):
299+
df.asfreq(freq=freq_depr)

pandas/tests/indexes/datetimes/methods/test_to_period.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ def test_dti_to_period_2monthish(self, freq_offset, freq_period):
9797
("2QE-SEP", "2Q-SEP"),
9898
("1YE", "1Y"),
9999
("2YE-MAR", "2Y-MAR"),
100-
("1YE", "1A"),
101-
("2YE-MAR", "2A-MAR"),
102100
],
103101
)
104-
def test_to_period_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):
102+
def test_to_period_frequency_M_Q_Y_deprecated(self, freq, freq_depr):
105103
# GH#9586
106104
msg = f"'{freq_depr[1:]}' is deprecated and will be removed "
107105
f"in a future version, please use '{freq[1:]}' instead."

pandas/tests/indexes/datetimes/test_date_range.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -800,13 +800,11 @@ def test_frequencies_H_T_S_L_U_N_deprecated(self, freq, freq_depr):
800800
@pytest.mark.parametrize(
801801
"freq,freq_depr",
802802
[
803-
("200YE", "200A"),
804803
("YE", "Y"),
805-
("2YE-MAY", "2A-MAY"),
806804
("YE-MAY", "Y-MAY"),
807805
],
808806
)
809-
def test_frequencies_A_deprecated_Y_renamed(self, freq, freq_depr):
807+
def test_frequencies_Y_renamed(self, freq, freq_depr):
810808
# GH#9586, GH#54275
811809
freq_msg = re.split("[0-9]*", freq, maxsplit=1)[1]
812810
freq_depr_msg = re.split("[0-9]*", freq_depr, maxsplit=1)[1]
@@ -836,6 +834,14 @@ def test_date_range_bday(self):
836834
assert idx[0] == sdate + 0 * offsets.BDay()
837835
assert idx.freq == "B"
838836

837+
@pytest.mark.parametrize("freq", ["200A", "2A-MAY"])
838+
def test_frequency_A_raises(self, freq):
839+
freq_msg = re.split("[0-9]*", freq, maxsplit=1)[1]
840+
msg = f"Invalid frequency: {freq_msg}"
841+
842+
with pytest.raises(ValueError, match=msg):
843+
date_range("1/1/2000", periods=2, freq=freq)
844+
839845

840846
class TestDateRangeTZ:
841847
"""Tests for date_range with timezones"""

pandas/tests/indexes/period/test_period_range.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -205,23 +205,6 @@ def test_constructor_U(self):
205205
with pytest.raises(ValueError, match="Invalid frequency: X"):
206206
period_range("2007-1-1", periods=500, freq="X")
207207

208-
@pytest.mark.parametrize(
209-
"freq,freq_depr",
210-
[
211-
("2Y", "2A"),
212-
("2Y", "2a"),
213-
("2Y-AUG", "2A-AUG"),
214-
("2Y-AUG", "2A-aug"),
215-
],
216-
)
217-
def test_a_deprecated_from_time_series(self, freq, freq_depr):
218-
# GH#52536
219-
msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
220-
f"future version. Please use '{freq[1:]}' instead."
221-
222-
with tm.assert_produces_warning(FutureWarning, match=msg):
223-
period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009")
224-
225208
@pytest.mark.parametrize("freq_depr", ["2H", "2MIN", "2S", "2US", "2NS"])
226209
def test_uppercase_freq_deprecated_from_time_series(self, freq_depr):
227210
# GH#52536, GH#54939
@@ -239,3 +222,10 @@ def test_lowercase_freq_deprecated_from_time_series(self, freq_depr):
239222

240223
with tm.assert_produces_warning(FutureWarning, match=msg):
241224
period_range(freq=freq_depr, start="1/1/2001", end="12/1/2009")
225+
226+
@pytest.mark.parametrize("freq", ["2A", "2a", "2A-AUG", "2A-aug"])
227+
def test_A_raises_from_time_series(self, freq):
228+
msg = f"Invalid frequency: {freq}"
229+
230+
with pytest.raises(ValueError, match=msg):
231+
period_range(freq=freq, start="1/1/2001", end="12/1/2009")

pandas/tests/resample/test_datetime_index.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -2047,11 +2047,9 @@ def test_resample_empty_series_with_tz():
20472047
("2QE-SEP", "2Q-SEP"),
20482048
("1YE", "1Y"),
20492049
("2YE-MAR", "2Y-MAR"),
2050-
("1YE", "1A"),
2051-
("2YE-MAR", "2A-MAR"),
20522050
],
20532051
)
2054-
def test_resample_M_Q_Y_A_deprecated(freq, freq_depr):
2052+
def test_resample_M_Q_Y_deprecated(freq, freq_depr):
20552053
# GH#9586
20562054
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed "
20572055
f"in a future version, please use '{freq[1:]}' instead."
@@ -2174,3 +2172,12 @@ def test_arrow_timestamp_resample(tz):
21742172
expected = Series(np.arange(5, dtype=np.float64), index=idx)
21752173
result = expected.resample("1D").mean()
21762174
tm.assert_series_equal(result, expected)
2175+
2176+
2177+
@pytest.mark.parametrize("freq", ["1A", "2A-MAR"])
2178+
def test_resample_A_raises(freq):
2179+
msg = f"Invalid frequency: {freq[1:]}"
2180+
2181+
s = Series(range(10), index=date_range("20130101", freq="d", periods=10))
2182+
with pytest.raises(ValueError, match=msg):
2183+
s.resample(freq).mean()

0 commit comments

Comments
 (0)