-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,9 +755,8 @@ def logical_method(self, other): | |
|
||
if other_is_scalar and not (other is libmissing.NA or lib.is_bool(other)): | ||
raise TypeError( | ||
"'other' should be pandas.NA or a bool. Got {} instead.".format( | ||
type(other).__name__ | ||
) | ||
f"'other' should be pandas.NA or a bool.\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know, done! |
||
Got {type(other).__name__} instead." | ||
) | ||
|
||
if not other_is_scalar and len(self) != len(other): | ||
|
@@ -772,7 +771,7 @@ def logical_method(self, other): | |
|
||
return BooleanArray(result, mask) | ||
|
||
name = "__{name}__".format(name=op.__name__) | ||
name = f"__{op.__name__}__" | ||
return set_function_name(logical_method, name, cls) | ||
|
||
@classmethod | ||
|
@@ -819,7 +818,7 @@ def cmp_method(self, other): | |
|
||
return BooleanArray(result, mask, copy=False) | ||
|
||
name = "__{name}__".format(name=op.__name__) | ||
name = f"__{op.__name__}" | ||
return set_function_name(cmp_method, name, cls) | ||
|
||
def _reduce(self, name, skipna=True, **kwargs): | ||
|
@@ -922,7 +921,7 @@ def boolean_arithmetic_method(self, other): | |
|
||
return self._maybe_mask_result(result, mask, other, op_name) | ||
|
||
name = "__{name}__".format(name=op_name) | ||
name = f"__{op_name}__" | ||
return set_function_name(boolean_arithmetic_method, name, cls) | ||
|
||
|
||
|
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 think @jbrockmendel prefers to define expressions like this in a variable first, instead of using them directly in the f-string.
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.
yes i do. thanks for keeping an eye out
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.
my preference would be to leave the .format syntax when message used more than once to help ensure consistency of error messages.
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.
Reverted to the original .format syntax, but will keep the earlier comments in mind for the future!