-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 6 commits
39b01ce
1d4dee9
3c80b2d
a1174ac
ad6f0e3
a606d55
47b6af6
721d152
52982ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from pandas import ( | ||
DataFrame, | ||
DatetimeIndex, | ||
PeriodIndex, | ||
Series, | ||
date_range, | ||
period_range, | ||
|
@@ -257,3 +258,36 @@ 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, error_msg", | ||
[ | ||
( | ||
"2MS", | ||
TypeError, | ||
'"2MS" is not supported as a period frequency', | ||
), | ||
( | ||
offsets.MonthBegin(), | ||
ValueError, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like those are caught before they reach your new error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting that Patrick and I chatted over Slack. Summary: The change in this PR raises an error for invalid strings. Another part of the code raises errors for for invalid offsets (That was already implemented, before this PR). |
||
( | ||
"Invalid offset: '<MonthBegin>' for converting " | ||
"time series with PeriodIndex." | ||
), | ||
), | ||
( | ||
offsets.DateOffset(months=2), | ||
ValueError, | ||
( | ||
"Invalid offset: '<DateOffset: months=2>' for converting " | ||
"time series with PeriodIndex." | ||
), | ||
), | ||
], | ||
) | ||
def test_asfreq_unsupported_freq(self, freq, error, error_msg): | ||
index = PeriodIndex(["2020-01-01", "2021-01-01"], freq="M") | ||
df = DataFrame({"a": Series([0, 1], index=index)}) | ||
|
||
with pytest.raises(error, match=error_msg): | ||
df.asfreq(freq=freq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in #56945 (review) I'm suggesting to raise if the return value of
to_offset(..., is_period=True)
doesn't have a_period_dtype_code
attributeIf that works, then it would resolve the linked issue too because
Period._maybe_convert_freq
would go down that path