-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Convert to fstring #30094
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
Convert to fstring #30094
Conversation
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.
few comments
@@ -223,7 +223,7 @@ cpdef _period_str_to_code(str freqstr): | |||
try: | |||
return _period_code_map[freqstr] | |||
except KeyError: | |||
raise ValueError(INVALID_FREQ_ERR_MSG.format(freqstr)) | |||
raise ValueError(INVALID_FREQ_ERR_MSG(freqstr)) |
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.
This looks like a typo?
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.
Hi,
In order to converting str.format() to f string I changed INVALID_FREQ_ERR_MSG definition from predefined string to lambda function. Now error message is defined in one place and is callable without .format().
Current definition:
INVALID_FREQ_ERR_MSG = lambda arg: f"Invalid frequency {arg}"
So now message is called as a function:
INVALID_FREQ_ERR_MSG(arg_str)
pandas/_libs/tslibs/period.pyx
Outdated
@@ -1209,8 +1209,8 @@ def period_format(int64_t value, int freq, object fmt=None): | |||
elif freq_group == 4000: # WK | |||
left = period_asfreq(value, freq, 6000, 0) | |||
right = period_asfreq(value, freq, 6000, 1) | |||
return '%s/%s' % (period_format(left, 6000), | |||
period_format(right, 6000)) | |||
return f'{period_format(left, 6000)}/{period_format(right, 6000)}' |
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.
Double quotes for f string please
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.
single quotes changed to double quotes
@@ -1598,7 +1599,7 @@ cdef class _Period: | |||
def __richcmp__(self, other, op): | |||
if is_period_object(other): | |||
if other.freq != self.freq: | |||
msg = DIFFERENT_FREQ.format(cls=type(self).__name__, | |||
msg = DIFFERENT_FREQ(cls=type(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.
You need an f string?
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.
same deal as abowe in frequencies.pyx file. DIFFERENT_FREQ is now a lambda function
My changes are causing problems, closing pull request . |
#29547