Skip to content

Commit a869a73

Browse files
authored
DEPR: correct error message in to_offset (#56141)
* correct warning message [skip ci] * DEPR: correct error message in to_offset
1 parent 4744064 commit a869a73

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

pandas/_libs/tslibs/offsets.pyx

+3
Original file line numberDiff line numberDiff line change
@@ -4735,6 +4735,9 @@ cpdef to_offset(freq, bint is_period=False):
47354735
f"for Period, please use \'Y{name[2:]}\' "
47364736
f"instead of \'{name}\'"
47374737
)
4738+
if (name.startswith("B") or
4739+
name.startswith("S") or name.startswith("C")):
4740+
raise ValueError(INVALID_FREQ_ERR_MSG.format(name))
47384741
else:
47394742
raise ValueError(
47404743
f"for Period, please use "

pandas/tests/indexes/period/test_period.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,11 @@ def test_map(self):
285285
"freq,freq_depr",
286286
[
287287
("2M", "2ME"),
288-
("2SM", "2SME"),
288+
("2Q-MAR", "2QE-MAR"),
289+
("2Y-FEB", "2YE-FEB"),
289290
],
290291
)
291-
def test_period_index_frequency_ME_SME_error_message(self, freq, freq_depr):
292+
def test_period_index_frequency_ME_error_message(self, freq, freq_depr):
292293
# GH#52064
293294
msg = f"for Period, please use '{freq[1:]}' instead of '{freq_depr[1:]}'"
294295

@@ -316,11 +317,10 @@ def test_a_deprecated_from_time_series(self, freq_depr):
316317
series = Series(1, index=index)
317318
assert isinstance(series, Series)
318319

319-
@pytest.mark.parametrize("freq_depr", ["2ME", "2QE", "2BQE", "2YE"])
320-
def test_period_index_frequency_error_message(self, freq_depr):
320+
@pytest.mark.parametrize("freq_depr", ["2SME", "2CBME", "2BYE"])
321+
def test_period_index_frequency_invalid_freq(self, freq_depr):
321322
# GH#9586
322-
msg = f"for Period, please use '{freq_depr[1:-1]}' "
323-
f"instead of '{freq_depr[1:]}'"
323+
msg = f"Invalid frequency: {freq_depr[1:]}"
324324

325325
with pytest.raises(ValueError, match=msg):
326326
period_range("2020-01", "2020-05", freq=freq_depr)

pandas/tests/resample/test_period_index.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -956,11 +956,8 @@ def test_resample_t_l_deprecated(self):
956956
("2M", "2ME"),
957957
("2Q", "2QE"),
958958
("2Q-FEB", "2QE-FEB"),
959-
("2BQ", "2BQE"),
960-
("2BQ-FEB", "2BQE-FEB"),
961959
("2Y", "2YE"),
962960
("2Y-MAR", "2YE-MAR"),
963-
("2BA-MAR", "2BYE-MAR"),
964961
],
965962
)
966963
def test_resample_frequency_ME_QE_YE_error_message(series_and_frame, freq, freq_depr):
@@ -978,3 +975,22 @@ def test_corner_cases_period(simple_period_range_series):
978975
# it works
979976
result = len0pts.resample("Y-DEC").mean()
980977
assert len(result) == 0
978+
979+
980+
@pytest.mark.parametrize(
981+
"freq_depr",
982+
[
983+
"2BME",
984+
"2CBME",
985+
"2SME",
986+
"2BQE-FEB",
987+
"2BYE-MAR",
988+
],
989+
)
990+
def test_resample_frequency_invalid_freq(series_and_frame, freq_depr):
991+
# GH#9586
992+
msg = f"Invalid frequency: {freq_depr[1:]}"
993+
994+
obj = series_and_frame
995+
with pytest.raises(ValueError, match=msg):
996+
obj.resample(freq_depr)

0 commit comments

Comments
 (0)