-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from 2 commits
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 |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. single quotes changed to double quotes |
||
) | ||
elif (freq_group == 5000 # BUS | ||
or freq_group == 6000): # DAY | ||
fmt = b'%Y-%m-%d' | ||
|
@@ -1455,7 +1455,7 @@ def extract_ordinals(ndarray[object] values, freq): | |
ordinals[i] = p.ordinal | ||
|
||
if p.freqstr != freqstr: | ||
msg = DIFFERENT_FREQ.format(cls="PeriodIndex", | ||
msg = DIFFERENT_FREQ(cls="PeriodIndex", | ||
own_freq=freqstr, | ||
other_freq=p.freqstr) | ||
raise IncompatibleFrequency(msg) | ||
|
@@ -1549,8 +1549,9 @@ cdef int64_t[:] localize_dt64arr_to_period(int64_t[:] stamps, | |
return result | ||
|
||
|
||
DIFFERENT_FREQ = ("Input has different freq={other_freq} " | ||
"from {cls}(freq={own_freq})") | ||
|
||
DIFFERENT_FREQ = lambda other_freq, cls, own_freq: f"Input has different freq={other_freq} " \ | ||
f"from {cls}(freq={own_freq})" | ||
|
||
|
||
class IncompatibleFrequency(ValueError): | ||
|
@@ -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 commentThe 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 commentThe 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 |
||
own_freq=self.freqstr, | ||
other_freq=other.freqstr) | ||
raise IncompatibleFrequency(msg) | ||
|
@@ -1640,7 +1641,7 @@ cdef class _Period: | |
if base == self.freq.rule_code: | ||
ordinal = self.ordinal + other.n | ||
return Period(ordinal=ordinal, freq=self.freq) | ||
msg = DIFFERENT_FREQ.format(cls=type(self).__name__, | ||
msg = DIFFERENT_FREQ(cls=type(self).__name__, | ||
own_freq=self.freqstr, | ||
other_freq=other.freqstr) | ||
raise IncompatibleFrequency(msg) | ||
|
@@ -1684,7 +1685,7 @@ cdef class _Period: | |
return Period(ordinal=ordinal, freq=self.freq) | ||
elif is_period_object(other): | ||
if other.freq != self.freq: | ||
msg = DIFFERENT_FREQ.format(cls=type(self).__name__, | ||
msg = DIFFERENT_FREQ(cls=type(self).__name__, | ||
own_freq=self.freqstr, | ||
other_freq=other.freqstr) | ||
raise IncompatibleFrequency(msg) | ||
|
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)