-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: NotImplementedError: Prefix not defined when slicing offset with loc #47547
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
REGR: NotImplementedError: Prefix not defined when slicing offset with loc #47547
Conversation
Hello @CloseChoice! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2022-08-22 20:30:59 UTC |
The problem in here is that we expect different types in this Is this on purpose? Shouldn't we be able to fix this issue by just implementing the |
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.
Agreed, I think we should figure out first, if _prefix is supposed to be defined
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
@CloseChoice thanks for the PR! (and sorry for that automated comment, it's not you who didn't update the PR, but it's a review that was lacking) I merged in main to fix the conflicts |
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.
Looks good to me.
I think we can try to clean up the situation around rule_code
in another PR that is not targeted for 1.4.x (should DateOffset have that defined? Should we actually pass something (greqstr/inferred_freq) to the parse function if rule_code isn't defined?)
if self.freq is None or hasattr(self.freq, "rule_code"): | ||
freq = self.freq | ||
except NotImplementedError: | ||
freq = getattr(self, "freqstr", getattr(self, "inferred_freq", None)) |
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 practice, I don't think we actually run into cases that need this. For example, freqstr
for the DateOffset case gives:
In [3]: d.index.freq
Out[3]: <DateOffset: days=1>
In [4]: d.index.freqstr
Out[4]: '<DateOffset: days=1>'
This "<DateOffset: days=1>" string is never going to be useful. But in practice, it also seems that parsing.parse_time_string
only actually uses freq
in very few cases. From a quick look, it only seems to use it if it is exactly equal to "M", or in case of parsing quarters. Here I could create a snippet where passing the freq actually impacts the result:
In [6]: parsing.parse_time_string("4q2022", "A-DEC")
Out[6]: (datetime.datetime(2022, 10, 1, 0, 0), 'quarter')
In [7]: parsing.parse_time_string("4q2022", "A-NOV")
Out[7]: (datetime.datetime(2022, 9, 1, 0, 0), 'quarter')
But, so this only is for quarterly offsets, and those do define a rule_code, so you probably don't run into this issue with that kind of freqs.
This line freq = getattr(self, "freqstr", getattr(self, "inferred_freq", None))
is restoring what we did before #42149, so that's good for a regression fix in the bug-fix release. But we should maybe also see if we can just remove it later on (and just pass None here if rule_code isn't defined?)
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 checked passing None if rule_code
isn't defined and a couple of tests fail in this case. Didn't look into it further though. But I think it should be possible to improve the situation around rule_code
.
First things first: Thanks once again for helping out and the very friendly tone of your comments. I really appreciate it. Yes, I totally agree that we should clean up
There are also a couple todos written in the code, so I think we could improve here quite some things. |
e7c2a26
to
54bd158
Compare
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 @CloseChoice typo to fix otherwise lgtm
Co-authored-by: Simon Hawkins <[email protected]>
…efined when slicing offset with loc
Thanks @CloseChoice !
Could you move that summary to a new issue to track this? |
… not defined when slicing offset with loc) (#48209) Backport PR #47547: REGR: NotImplementedError: Prefix not defined when slicing offset with loc Co-authored-by: Tobias Pitters <[email protected]>
…h loc (pandas-dev#47547) Co-authored-by: Joris Van den Bossche <[email protected]> Co-authored-by: Simon Hawkins <[email protected]>
doc/source/whatsnew/v1.4.4.rst
file if fixing a bug or adding a new feature.