Skip to content

Commit

Permalink
TST: assert that informative error is raised when offset not supporte…
Browse files Browse the repository at this point in the history
…d as a period frequency is passed to DataFrame.asfreq (pandas-dev#56758)

* style

* add test

* pytest.raises

* freqstr

* add test for offsets

* rearrange per comment

* fixup

* fixup

---------

Co-authored-by: MarcoGorelli <[email protected]>
  • Loading branch information
2 people authored and pmhatre1 committed May 7, 2024
1 parent 3886d2d commit b33b0a2
Showing 1 changed file with 26 additions and 0 deletions.
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)

0 comments on commit b33b0a2

Please sign in to comment.