Skip to content

Commit dfb3f6c

Browse files
TST: assert that informative error is raised when offset not supported as a period frequency is passed to DataFrame.asfreq (#56758)
* style * add test * pytest.raises * freqstr * add test for offsets * rearrange per comment * fixup * fixup --------- Co-authored-by: MarcoGorelli <[email protected]>
1 parent c064308 commit dfb3f6c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/tests/frame/methods/test_asfreq.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandas import (
99
DataFrame,
1010
DatetimeIndex,
11+
PeriodIndex,
1112
Series,
1213
date_range,
1314
period_range,
@@ -257,3 +258,28 @@ def test_asfreq_frequency_M_Q_Y_A_deprecated(self, freq, freq_depr):
257258
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
258259
result = df.asfreq(freq=freq_depr)
259260
tm.assert_frame_equal(result, expected)
261+
262+
@pytest.mark.parametrize(
263+
"freq, error_msg",
264+
[
265+
(
266+
"2MS",
267+
"MS is not supported as period frequency",
268+
),
269+
(
270+
offsets.MonthBegin(),
271+
r"\<MonthBegin\> is not supported as period frequency",
272+
),
273+
(
274+
offsets.DateOffset(months=2),
275+
r"\<DateOffset: months=2\> is not supported as period frequency",
276+
),
277+
],
278+
)
279+
def test_asfreq_unsupported_freq(self, freq, error_msg):
280+
# https://github.com/pandas-dev/pandas/issues/56718
281+
index = PeriodIndex(["2020-01-01", "2021-01-01"], freq="M")
282+
df = DataFrame({"a": Series([0, 1], index=index)})
283+
284+
with pytest.raises(ValueError, match=error_msg):
285+
df.asfreq(freq=freq)

0 commit comments

Comments
 (0)