-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
ENH: raise ValueError if invalid period freq pass to asfreq when the index of df is a PeriodIndex #56945
ENH: raise ValueError if invalid period freq pass to asfreq when the index of df is a PeriodIndex #56945
Changes from 6 commits
39f59c4
2b602bd
ff1c6e7
fff7c9d
a389d11
d2ea914
3735e23
b1e6ba6
c41557a
17fd84c
721637b
deea30d
4cbcc5e
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 |
---|---|---|
|
@@ -41,20 +41,21 @@ class TestPeriodDisallowedFreqs: | |
def test_offsets_not_supported(self, freq, freq_msg): | ||
# GH#55785 | ||
msg = f"{freq_msg} is not supported as period frequency" | ||
with pytest.raises(TypeError, match=msg): | ||
with pytest.raises(ValueError, match=msg): | ||
Period(year=2014, freq=freq) | ||
|
||
def test_custom_business_day_freq_raises(self): | ||
# GH#52534 | ||
msg = "CustomBusinessDay is not supported as period frequency" | ||
with pytest.raises(TypeError, match=msg): | ||
msg = "C is not supported as period frequency" | ||
with pytest.raises(ValueError, match=msg): | ||
Period("2023-04-10", freq="C") | ||
msg = "CustomBusinessDay is not supported as period frequency" | ||
with pytest.raises(TypeError, match=msg): | ||
Period("2023-04-10", freq=offsets.CustomBusinessDay()) | ||
|
||
def test_invalid_frequency_error_message(self): | ||
msg = "WeekOfMonth is not supported as period frequency" | ||
with pytest.raises(TypeError, match=msg): | ||
msg = "WOM-1MON is not supported as period frequency" | ||
with pytest.raises(ValueError, match=msg): | ||
Period("2012-01-02", freq="WOM-1MON") | ||
Comment on lines
-56
to
60
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. nice! yeah better to match what the user passed if possible, good one 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. I am unsure if it's possible to do this assignment on line 4841, if I do it
I get failures. The reason: if we replace return freq with the delta = freq, we go to the line 4962 and assign delta to None and then on line 4965 we raise a ValueError. Instead of the assignment delta = freq I added the check
|
||
|
||
def test_invalid_frequency_period_error_message(self): | ||
|
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.
maybe on line 4841, we can do
so then that gets validated too?
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.
is it possible to do this assignment on line 4841 as well? just in case an offset which isn't valid for periods is passed
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.
I am unsure if it's possible. I tried to do this assignment on line 4841
but then I got failures.
The reason: if we replace
return freq
with thedelta = freq
, we go to the line 4962 and assign delta to None and then on line 4965 we raise a ValueError.Which is why instead of the assignment
delta = freq
I added the checkThere 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.
I think you can just move this down to before
elif PyDelta_Check(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.
thanks, I saw you already made commit for it