Skip to content

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

Closed
wants to merge 4 commits into from
Closed

Convert to fstring #30094

wants to merge 4 commits into from

Conversation

Behemkot
Copy link
Contributor

@Behemkot Behemkot commented Dec 5, 2019

#29547

  • pandas/_libs/tslibs/frequencies.pyx
  • pandas/_libs/tslibs/period.pyx
  • pandas/_libs/tslibs/strptime.pyx

@alimcmaster1 alimcmaster1 added Code Style Code style, linting, code_checks Clean labels Dec 5, 2019
Copy link
Member

@alimcmaster1 alimcmaster1 left a 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))
Copy link
Member

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?

Copy link
Contributor Author

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)

@@ -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)}'
Copy link
Member

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

Copy link
Contributor Author

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__,
Copy link
Member

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?

Copy link
Contributor Author

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

@Behemkot Behemkot closed this Dec 6, 2019
@Behemkot Behemkot reopened this Dec 6, 2019
@Behemkot Behemkot closed this Dec 6, 2019
@Behemkot Behemkot reopened this Dec 6, 2019
@Behemkot Behemkot closed this Dec 6, 2019
@Behemkot Behemkot reopened this Dec 6, 2019
@Behemkot
Copy link
Contributor Author

Behemkot commented Dec 6, 2019

My changes are causing problems, closing pull request .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants