Skip to content

Updated .format() to f-strings #30027

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 4 commits into from
Dec 5, 2019
Merged

Updated .format() to f-strings #30027

merged 4 commits into from
Dec 5, 2019

Conversation

dlalap
Copy link
Contributor

@dlalap dlalap commented Dec 4, 2019

@alimcmaster1 alimcmaster1 added Code Style Code style, linting, code_checks Clean labels Dec 4, 2019
@@ -846,7 +846,7 @@ def _parser_dispatch(flavor):


def _print_as_set(s) -> str:
return "{" + "{arg}".format(arg=", ".join(pprint_thing(el) for el in s)) + "}"
return f"{{{', '.join(pprint_thing(el) for el in s)}}}"
Copy link
Member

Choose a reason for hiding this comment

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

join on previous line pls

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Looks good if you can address @jbrockmendel suggestions and I think CI failures are unrelated / have been fixed on master since this was created.

To be sure, can you locally on your f-strings branch run:

git fetch upstream
git merge upstream/master
git push origin f-strings

I think should get CI green for this. Flag me down at PyData if you have any questions

@jreback jreback added this to the 1.0 milestone Dec 4, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

@@ -846,7 +846,8 @@ def _parser_dispatch(flavor):


def _print_as_set(s) -> str:
return "{" + "{arg}".format(arg=", ".join(pprint_thing(el) for el in s)) + "}"
arg = ", ".join(pprint_thing(el) for el in s)
return f"{{{arg}}}"
Copy link
Member

Choose a reason for hiding this comment

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

is this adding a layer of braces?

Copy link
Member

Choose a reason for hiding this comment

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

you might be able to get rid of the pprint_thing, not sure

Copy link
Member

Choose a reason for hiding this comment

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

The double brace is how to add a literal brace in an f-string, so looks OK

@@ -616,8 +616,8 @@ def _build_xpath_expr(attrs) -> str:
if "class_" in attrs:
attrs["class"] = attrs.pop("class_")

s = [f"@{k}={repr(v)}" for k, v in attrs.items()]
return "[{expr}]".format(expr=" and ".join(s))
s = " and ".join([f"@{k}={repr(v)}" for k, v in attrs.items()])
Copy link
Member

Choose a reason for hiding this comment

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

if you end up making another pass through this file, can you do this in two lines? i.e. keep s as it is now and do the join in a separate step

@WillAyd WillAyd merged commit a3ba3e1 into pandas-dev:master Dec 5, 2019
@WillAyd
Copy link
Member

WillAyd commented Dec 5, 2019

Thanks @dlalap congrats on first PR. If you'd like to address some suggestions from @jbrockmendel in a follow up would certainly welcome, along with any other contributions

proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
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.

5 participants