Skip to content

CLN: Update old .format to f-string #30547

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

Merged
merged 5 commits into from
Dec 30, 2019

Conversation

thepaullee
Copy link
Contributor

Reviewed and updated to f-string for:
pandas/compat/pickle_compat.py
pandas/_config/config.py
pandas/core/arrays/boolean.py

Marking pickle_compat.py as done but I left the existing .format as is, as I believe this is a good use case for .format

Paul Lee added 3 commits December 29, 2019 13:23
Reviewed and updated to f-string for:
pandas/compat/pickle_compat.py
pandas/_config/config.py
pandas/core/arrays/boolean.py

Contributes to GH29547
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments, other than that looks good. Thanks @thepaullee


for i, p in enumerate(path[:-1]):
if not isinstance(cursor, dict):
raise OptionError(msg.format(option=".".join(path[:i])))
raise OptionError(
f"Path prefix to option '{'.'.join(path[:i])}' is already an option"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @jbrockmendel prefers to define expressions like this in a variable first, instead of using them directly in the f-string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i do. thanks for keeping an eye out

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my preference would be to leave the .format syntax when message used more than once to help ensure consistency of error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted to the original .format syntax, but will keep the earlier comments in mind for the future!

"'other' should be pandas.NA or a bool. Got {} instead.".format(
type(other).__name__
)
f"'other' should be pandas.NA or a bool.\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid backslashes in general, you can close the string here, and start it again in the next line, and they'll concatenate. Just leave a space at the end of this first string, and just make the second a 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.

Good to know, done!

@datapythonista datapythonista added Clean Code Style Code style, linting, code_checks labels Dec 29, 2019
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, other than that lgtm. Thanks @thepaullee

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @thepaullee

@simonjayhawkins simonjayhawkins added this to the 1.0 milestone Dec 30, 2019
@simonjayhawkins simonjayhawkins merged commit 2ec41bd into pandas-dev:master Dec 30, 2019
@simonjayhawkins
Copy link
Member

Thanks @thepaullee

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.

4 participants