Skip to content

Commit af18cd1

Browse files
committed
CLN: use f-strings where possible
Mechanically transformed with `flynt -tc -a -v`
1 parent edbac36 commit af18cd1

File tree

110 files changed

+335
-343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+335
-343
lines changed

pandas/_config/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def register_option(
499499
path = key.split(".")
500500

501501
for k in path:
502-
if not re.match("^" + tokenize.Name + "$", k):
502+
if not re.match(f"^{tokenize.Name}$", k):
503503
raise ValueError(f"{k} is not a valid identifier")
504504
if keyword.iskeyword(k):
505505
raise ValueError(f"{k} is a python keyword")
@@ -707,7 +707,7 @@ def pp_options_list(keys: Iterable[str], width: int = 80, _print: bool = False):
707707
from textwrap import wrap
708708

709709
def pp(name: str, ks: Iterable[str]) -> list[str]:
710-
pfx = "- " + name + ".[" if name else ""
710+
pfx = f"- {name}.[" if name else ""
711711
ls = wrap(
712712
", ".join(ks),
713713
width,
@@ -716,7 +716,7 @@ def pp(name: str, ks: Iterable[str]) -> list[str]:
716716
break_long_words=False,
717717
)
718718
if ls and ls[-1] and name:
719-
ls[-1] = ls[-1] + "]"
719+
ls[-1] = f"{ls[-1]}]"
720720
return ls
721721

722722
ls: list[str] = []

pandas/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ def spmatrix(request):
17731773
"""
17741774
from scipy import sparse
17751775

1776-
return getattr(sparse, request.param + "_matrix")
1776+
return getattr(sparse, f"{request.param}_matrix")
17771777

17781778

17791779
@pytest.fixture(

pandas/core/arraylike.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any)
304304
# well. Previously this raised an internal ValueError. We might
305305
# support it someday, so raise a NotImplementedError.
306306
raise NotImplementedError(
307-
"Cannot apply ufunc {} to mixed DataFrame and Series "
308-
"inputs.".format(ufunc)
307+
f"Cannot apply ufunc {ufunc} to mixed DataFrame and Series inputs."
309308
)
310309
axes = self.axes
311310
for obj in alignable[1:]:

pandas/core/arrays/categorical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,7 +2166,7 @@ def _repr_categories_info(self) -> str:
21662166
start = True
21672167
cur_col_len = len(levheader) # header
21682168
sep_len, sep = (3, " < ") if self.ordered else (2, ", ")
2169-
linesep = sep.rstrip() + "\n" # remove whitespace
2169+
linesep = f"{sep.rstrip()}\n" # remove whitespace
21702170
for val in category_strs:
21712171
if max_width != 0 and cur_col_len + sep_len + len(val) > max_width:
21722172
levstring += linesep + (" " * (len(levheader) + 1))
@@ -2177,7 +2177,7 @@ def _repr_categories_info(self) -> str:
21772177
levstring += val
21782178
start = False
21792179
# replace to simple save space by
2180-
return levheader + "[" + levstring.replace(" < ... < ", " ... ") + "]"
2180+
return f"{levheader}[{levstring.replace(' < ... < ', ' ... ')}]"
21812181

21822182
def _repr_footer(self) -> str:
21832183
info = self._repr_categories_info()

pandas/core/arrays/masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
10581058
data = self.to_numpy("float64", na_value=np.nan)
10591059

10601060
# median, var, std, skew, kurt, idxmin, idxmax
1061-
op = getattr(nanops, "nan" + name)
1061+
op = getattr(nanops, f"nan{name}")
10621062
result = op(data, axis=0, skipna=skipna, mask=mask, **kwargs)
10631063

10641064
if np.isnan(result):

pandas/core/arrays/string_arrow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ def _str_contains(
317317
return result
318318

319319
def _str_startswith(self, pat: str, na=None):
320-
pat = "^" + re.escape(pat)
320+
pat = f"^{re.escape(pat)}"
321321
return self._str_contains(pat, na=na, regex=True)
322322

323323
def _str_endswith(self, pat: str, na=None):
324-
pat = re.escape(pat) + "$"
324+
pat = f"{re.escape(pat)}$"
325325
return self._str_contains(pat, na=na, regex=True)
326326

327327
def _str_replace(
@@ -345,14 +345,14 @@ def _str_match(
345345
self, pat: str, case: bool = True, flags: int = 0, na: Scalar | None = None
346346
):
347347
if not pat.startswith("^"):
348-
pat = "^" + pat
348+
pat = f"^{pat}"
349349
return self._str_contains(pat, case, flags, na, regex=True)
350350

351351
def _str_fullmatch(
352352
self, pat, case: bool = True, flags: int = 0, na: Scalar | None = None
353353
):
354354
if not pat.endswith("$") or pat.endswith("//$"):
355-
pat = pat + "$"
355+
pat = f"{pat}$"
356356
return self._str_match(pat, case, flags, na)
357357

358358
def _str_isalnum(self):

pandas/core/computation/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def visit(self, node, **kwargs):
410410
e.msg = "Python keyword not valid identifier in numexpr query"
411411
raise e
412412

413-
method = "visit_" + type(node).__name__
413+
method = f"visit_{type(node).__name__}"
414414
visitor = getattr(self, method)
415415
return visitor(node, **kwargs)
416416

pandas/core/computation/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def create_valid_python_identifier(name: str) -> str:
5959
)
6060

6161
name = "".join([special_characters_replacements.get(char, char) for char in name])
62-
name = "BACKTICK_QUOTED_STRING_" + name
62+
name = f"BACKTICK_QUOTED_STRING_{name}"
6363

6464
if not name.isidentifier():
6565
raise SyntaxError(f"Could not convert '{name}' to a valid Python identifier.")

pandas/core/computation/scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def _get_vars(self, stack, scopes: list[str]) -> None:
250250
variables = itertools.product(scopes, stack)
251251
for scope, (frame, _, _, _, _, _) in variables:
252252
try:
253-
d = getattr(frame, "f_" + scope)
253+
d = getattr(frame, f"f_{scope}")
254254
self.scope = DeepChainMap(self.scope.new_child(d))
255255
finally:
256256
# won't remove it, but DECREF it

pandas/core/dtypes/dtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ def __hash__(self) -> int:
804804
def __eq__(self, other: Any) -> bool:
805805
if isinstance(other, str):
806806
if other.startswith("M8["):
807-
other = "datetime64[" + other[3:]
807+
other = f"datetime64[{other[3:]}"
808808
return other == self.name
809809

810810
return (

0 commit comments

Comments
 (0)