-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-45619: [Python] Use f-string instead of string.format #45629
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
GH-45619: [Python] Use f-string instead of string.format #45629
Conversation
|
We have many |
|
@kou Thank you for the reminder🙏. I personally prefer to implement all changes within a single PR, so I am converting the PR to draft status. |
|
I have already changed all the files under the pyarrow folder. As discussed in #45619, certain scenarios where the template is reused across multiple methods using |
raulcd
left a comment
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.
Thanks for the PR, could you take a look on the CI failures:
https://github.com/apache/arrow/actions/runs/13620611692/job/38077510062?pr=45629#step:6:8540
There are some cases were the expected doctest is failing due to the changes.
python/pyarrow/_acero.pyx
Outdated
|
|
||
| def __repr__(self): | ||
| return "<pyarrow.acero.Declaration>\n{0}".format(str(self)) | ||
| return f"<pyarrow.acero.Declaration>\n{str(self)}" |
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.
str is implicit in f-strings, you don't need to call it explicitly. Example:
>>> from decimal import Decimal
>>> d = Decimal('1.500')
>>> repr(d)
"Decimal('1.500')"
>>> str(d)
'1.500'
>>> f"d is {d}"
'd is 1.500'
>>> f"d is {d!r}"
"d is Decimal('1.500')"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.
Thanks for review! I will change this.
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.
Solved in cef7a3b
You can, but you don't have to. It's as you prefer. |
Got it! I prefer to update all files in this PR, so I will mark it as a draft until all changes are made. Thanks! |
|
"C GLib & Ruby / AMD64 Windows MSVC GLib" will be fixed by #46006 . |
raulcd
left a comment
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.
@chilin0525 will you have some time to rebase main and fix the conflicts?
|
@raulcd I've rebased onto main and resolved the conflicts. The CI error looks unrelated to this change. Let me know if there's anything else I should adjust. Thanks! |
|
@github-actions crossbow submit -g python |
raulcd
left a comment
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.
I've applied some minor suggestions and fixed a new conflict with main. If CI is successful I am going to merge.
|
Revision: 7079403 Submitted crossbow builds: ursacomputing/crossbow @ actions-11bf920665 |
|
The CI failures are unrelated. The Python 3.10 are related to the test_gdb.py issue: |
|
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 992bee2. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about 11 possible false positives for unstable benchmarks that are known to sometimes produce them. |
Rationale for this change
See #45619.
What changes are included in this PR?
Refactor using f-string instead of
string.format. But do not use f-string for following case,string.formatallows passing parameters, making the code more reusable.arrow/python/pyarrow/parquet/core.py
Lines 1624 to 1695 in 0fbf982
Are these changes tested?
Via CI.
Are there any user-facing changes?
No.
string.format#45619