Skip to content

Commit 06dd579

Browse files
committed
CLN: apply manual f-string fixes inspired by flynt -tc
1 parent 6d3e298 commit 06dd579

36 files changed

+89
-93
lines changed

asv_bench/benchmarks/categoricals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def setup(self):
8989
)
9090

9191
for col in ("int", "float", "timestamp"):
92-
self.df[col + "_as_str"] = self.df[col].astype(str)
92+
self.df[f"{col}_as_str"] = self.df[col].astype(str)
9393

9494
for col in self.df.columns:
9595
self.df[col] = self.df[col].astype("category")

asv_bench/benchmarks/frame_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def setup(self):
125125
self.df = DataFrame(np.random.randn(N * 10, N))
126126
self.df2 = DataFrame(np.random.randn(N * 50, 10))
127127
self.df3 = DataFrame(
128-
np.random.randn(N, 5 * N), columns=["C" + str(c) for c in range(N * 5)]
128+
np.random.randn(N, 5 * N), columns=[f"C{c}" for c in range(N * 5)]
129129
)
130130
self.df4 = DataFrame(np.random.randn(N * 1000, 10))
131131

asv_bench/benchmarks/inference.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ def time_unique_date_strings(self, cache, count):
166166

167167

168168
class ToDatetimeISO8601:
169+
sep_format = "%Y-%m-%d %H:%M:%S"
170+
nosep_format = "%Y%m%d %H:%M:%S"
169171
def setup(self):
170172
rng = date_range(start="1/1/2000", periods=20000, freq="H")
171-
self.strings = rng.strftime("%Y-%m-%d %H:%M:%S").tolist()
172-
self.strings_nosep = rng.strftime("%Y%m%d %H:%M:%S").tolist()
173-
self.strings_tz_space = [
174-
x.strftime("%Y-%m-%d %H:%M:%S") + " -0800" for x in rng
175-
]
176-
self.strings_zero_tz = [x.strftime("%Y-%m-%d %H:%M:%S") + "Z" for x in rng]
173+
self.strings = rng.strftime(self.sep_format).tolist()
174+
self.strings_nosep = rng.strftime(self.nosep_format).tolist()
175+
self.strings_tz_space = [f"{x.strftime(self.sep_format)} -0800" for x in rng]
176+
self.strings_zero_tz = [f"{x.strftime(self.sep_format)}Z" for x in rng]
177177

178178
def time_iso8601(self):
179179
to_datetime(self.strings)
@@ -182,10 +182,10 @@ def time_iso8601_nosep(self):
182182
to_datetime(self.strings_nosep)
183183

184184
def time_iso8601_format(self):
185-
to_datetime(self.strings, format="%Y-%m-%d %H:%M:%S")
185+
to_datetime(self.strings, format=self.sep_format)
186186

187187
def time_iso8601_format_no_sep(self):
188-
to_datetime(self.strings_nosep, format="%Y%m%d %H:%M:%S")
188+
to_datetime(self.strings_nosep, format=self.nosep_format)
189189

190190
def time_iso8601_tz_spaceformat(self):
191191
to_datetime(self.strings_tz_space)

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
@@ -1770,7 +1770,7 @@ def spmatrix(request):
17701770
"""
17711771
from scipy import sparse
17721772

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

17751775

17761776
@pytest.fixture(

pandas/core/arrays/categorical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@ def _repr_categories_info(self) -> str:
21222122
start = True
21232123
cur_col_len = len(levheader) # header
21242124
sep_len, sep = (3, " < ") if self.ordered else (2, ", ")
2125-
linesep = sep.rstrip() + "\n" # remove whitespace
2125+
linesep = f"{sep.rstrip()}\n" # remove whitespace
21262126
for val in category_strs:
21272127
if max_width != 0 and cur_col_len + sep_len + len(val) > max_width:
21282128
levstring += linesep + (" " * (len(levheader) + 1))
@@ -2133,7 +2133,7 @@ def _repr_categories_info(self) -> str:
21332133
levstring += val
21342134
start = False
21352135
# replace to simple save space by
2136-
return levheader + "[" + levstring.replace(" < ... < ", " ... ") + "]"
2136+
return f"{levheader}[{levstring.replace(' < ... < ', ' ... ')}]"
21372137

21382138
def _repr_footer(self) -> str:
21392139
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.")

0 commit comments

Comments
 (0)