Skip to content

TST: assert that informative error is raised when offset not supported as a period frequency is passed to DataFrame.asfreq #56758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

26 changes: 26 additions & 0 deletions pandas/tests/frame/methods/test_asfreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pandas import (
DataFrame,
DatetimeIndex,
PeriodIndex,
Series,
date_range,
period_range,
Expand Down Expand Up @@ -257,3 +258,28 @@ def test_asfreq_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
result = df.asfreq(freq=freq_depr)
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"freq, error_msg",
[
(
"2MS",
"MS is not supported as period frequency",
),
(
offsets.MonthBegin(),
r"\<MonthBegin\> is not supported as period frequency",
),
(
offsets.DateOffset(months=2),
r"\<DateOffset: months=2\> is not supported as period frequency",
),
],
)
def test_asfreq_unsupported_freq(self, freq, error_msg):
# https://github.com/pandas-dev/pandas/issues/56718
index = PeriodIndex(["2020-01-01", "2021-01-01"], freq="M")
df = DataFrame({"a": Series([0, 1], index=index)})

with pytest.raises(ValueError, match=error_msg):
df.asfreq(freq=freq)