-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
base: main
Are you sure you want to change the base?
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 |
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
@@ -553,7 +553,7 @@ cdef class Declaration(_Weakrefable): | |||
return frombytes(GetResultValue(DeclarationToString(self.decl))) | |||
|
|||
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! |
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.format
allows 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