-
-
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 1 commit
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 |
---|---|---|
|
@@ -210,18 +210,6 @@ def _resolution_obj(self) -> Resolution: | |
**_shared_doc_kwargs, | ||
) | ||
def asfreq(self, freq=None, how: str = "E") -> Self: | ||
if isinstance(freq, str): | ||
offset = to_offset(freq, is_period=True) | ||
if hasattr(offset, "_period_dtype_code"): | ||
freq = freq_to_period_freqstr(offset.n, offset.name) | ||
elif offset.name == freq.replace(f"{offset.n}", ""): | ||
raise ValueError( | ||
f"Invalid offset: '{offset.name}' for converting time series " | ||
f"with PeriodIndex." | ||
) | ||
else: | ||
raise ValueError(INVALID_FREQ_ERR_MSG.format(f"{freq}")) | ||
|
||
arr = self._data.asfreq(freq, how) | ||
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. can you follow this EDIT: as mentioned in the review, it might be better to go all the way down and do this validation within 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. thanks, I did as you suggested and moved this validation to |
||
return type(self)._simple_new(arr, name=self.name) | ||
|
||
|
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