Skip to content

Commit d21f19c

Browse files
authored
STYLE: fix pylint consider-using-f-string issues (#49515)
Refs #48855
1 parent 57d8d3a commit d21f19c

File tree

14 files changed

+19
-16
lines changed

14 files changed

+19
-16
lines changed

asv_bench/benchmarks/io/hdf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def setup(self):
4343
np.random.randn(N, 100), index=date_range("1/1/2000", periods=N)
4444
)
4545
self.df_dc = DataFrame(
46-
np.random.randn(N, 10), columns=["C%03d" % i for i in range(10)]
46+
np.random.randn(N, 10), columns=[f"C{i:03d}" for i in range(10)]
4747
)
4848

4949
self.fname = "__test__.h5"

doc/scripts/eval_performance.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def bench_with(n, times=10, repeat=3, engine="numexpr"):
1717
return (
1818
np.array(
1919
timeit(
20-
"df.eval(s, engine=%r)" % engine,
20+
f"df.eval(s, engine={repr(engine)})",
2121
setup=setup_common % (n, setup_with),
2222
repeat=repeat,
2323
number=times,
@@ -34,7 +34,7 @@ def bench_subset(n, times=20, repeat=3, engine="numexpr"):
3434
return (
3535
np.array(
3636
timeit(
37-
"df.query(s, engine=%r)" % engine,
37+
f"df.query(s, engine={repr(engine)})",
3838
setup=setup_common % (n, setup_subset),
3939
repeat=repeat,
4040
number=times,
@@ -55,7 +55,7 @@ def bench(mn=3, mx=7, num=100, engines=("python", "numexpr"), verbose=False):
5555
for engine in engines:
5656
for i, n in enumerate(r):
5757
if verbose & (i % 10 == 0):
58-
print("engine: %r, i == %d" % (engine, i))
58+
print(f"engine: {repr(engine)}, i == {i:d}")
5959
ev_times = bench_with(n, times=1, repeat=1, engine=engine)
6060
ev.loc[i, engine] = np.mean(ev_times)
6161
qu_times = bench_subset(n, times=1, repeat=1, engine=engine)

pandas/_version.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=consider-using-f-string
12
# This file helps to compute a version number in source trees obtained from
23
# git-archive tarball (such as those provided by GitHub's download-from-tag
34
# feature). Distribution tarballs (built by setup.py sdist) and build

pandas/core/arraylike.py

+1-2
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/generic.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import collections
55
from datetime import timedelta
6-
import functools
76
import gc
87
import json
98
import operator
@@ -4596,7 +4595,7 @@ def add_prefix(self: NDFrameT, prefix: str, axis: Axis | None = None) -> NDFrame
45964595
2 3 5
45974596
3 4 6
45984597
"""
4599-
f = functools.partial("{prefix}{}".format, prefix=prefix)
4598+
f = lambda x: f"{prefix}{x}"
46004599

46014600
axis_name = self._info_axis_name
46024601
if axis is not None:
@@ -4670,7 +4669,7 @@ def add_suffix(self: NDFrameT, suffix: str, axis: Axis | None = None) -> NDFrame
46704669
2 3 5
46714670
3 4 6
46724671
"""
4673-
f = functools.partial("{}{suffix}".format, suffix=suffix)
4672+
f = lambda x: f"{x}{suffix}"
46744673

46754674
axis_name = self._info_axis_name
46764675
if axis is not None:

pandas/tests/config/test_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def test_validation(self):
227227

228228
validator = cf.is_one_of_factory([None, cf.is_callable])
229229
cf.register_option("b", lambda: None, "doc", validator=validator)
230+
# pylint: disable-next=consider-using-f-string
230231
cf.set_option("b", "%.1f".format) # Formatter is callable
231232
cf.set_option("b", None) # Formatter is none (default)
232233
with pytest.raises(ValueError, match="Value must be a callable"):

pandas/tests/indexing/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def run_tests(df, rhs, right_loc, right_iloc):
706706
# make frames multi-type & re-run tests
707707
for frame in [df, rhs, right_loc, right_iloc]:
708708
frame["joe"] = frame["joe"].astype("float64")
709-
frame["jolie"] = frame["jolie"].map("@{}".format)
709+
frame["jolie"] = frame["jolie"].map(lambda x: f"@{x}")
710710
right_iloc["joe"] = [1.0, "@-28", "@-20", "@-12", 17.0]
711711
right_iloc["jolie"] = ["@2", -26.0, -18.0, -10.0, "@18"]
712712
run_tests(df, rhs, right_loc, right_iloc)

pandas/tests/io/excel/test_openpyxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_to_excel_with_openpyxl_engine(ext):
256256
df2 = DataFrame({"B": np.linspace(1, 20, 10)})
257257
df = pd.concat([df1, df2], axis=1)
258258
styled = df.style.applymap(
259-
lambda val: "color: %s" % ("red" if val < 0 else "black")
259+
lambda val: f"color: {'red' if val < 0 else 'black'}"
260260
).highlight_max()
261261

262262
styled.to_excel(filename, engine="openpyxl")

pandas/tests/io/formats/style/test_html.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -802,14 +802,15 @@ def test_rendered_links(type, text, exp, found):
802802
df = DataFrame([0], index=[text])
803803
styler = df.style.format_index(hyperlinks="html")
804804

805-
rendered = '<a href="{0}" target="_blank">{0}</a>'.format(found)
805+
rendered = f'<a href="{found}" target="_blank">{found}</a>'
806806
result = styler.to_html()
807807
assert (rendered in result) is exp
808808
assert (text in result) is not exp # test conversion done when expected and not
809809

810810

811811
def test_multiple_rendered_links():
812812
links = ("www.a.b", "http://a.c", "https://a.d", "ftp://a.e")
813+
# pylint: disable-next=consider-using-f-string
813814
df = DataFrame(["text {} {} text {} {}".format(*links)])
814815
result = df.style.format(hyperlinks="html").to_html()
815816
href = '<a href="{0}" target="_blank">{0}</a>'

pandas/tests/io/formats/test_to_latex.py

+1
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ def test_to_latex_multiindex_names(self, name0, name1, axes):
13351335
placeholder = "{}" if any(names) and 1 in axes else " "
13361336
col_names = [n if (bool(n) and 1 in axes) else placeholder for n in names]
13371337
observed = df.to_latex()
1338+
# pylint: disable-next=consider-using-f-string
13381339
expected = r"""\begin{tabular}{llrrrr}
13391340
\toprule
13401341
& %s & \multicolumn{2}{l}{1} & \multicolumn{2}{l}{2} \\

pandas/tests/io/test_fsspec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def test_from_s3_csv(s3_resource, tips_file, s3so):
211211
@td.skip_if_no("s3fs")
212212
def test_s3_protocols(s3_resource, tips_file, protocol, s3so):
213213
tm.assert_equal(
214-
read_csv("%s://pandas-test/tips.csv" % protocol, storage_options=s3so),
214+
read_csv(f"{protocol}://pandas-test/tips.csv", storage_options=s3so),
215215
read_csv(tips_file),
216216
)
217217

pandas/tests/io/test_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def test_to_html_compat(self):
125125
c_idx_names=False,
126126
r_idx_names=False,
127127
)
128-
.applymap("{:.3f}".format)
129-
.astype(float)
128+
# pylint: disable-next=consider-using-f-string
129+
.applymap("{:.3f}".format).astype(float)
130130
)
131131
out = df.to_html()
132132
res = self.read_html(out, attrs={"class": "dataframe"}, index_col=0)[0]

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ disable = [
7878
"used-before-assignment",
7979

8080
# pylint type "C": convention, for programming standard violation
81-
"consider-using-f-string",
8281
"import-outside-toplevel",
8382
"invalid-name",
8483
"line-too-long",

versioneer.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Version: 0.19
2+
# pylint: disable=consider-using-f-string
23

34
"""The Versioneer - like a rocketeer, but for versions.
45
@@ -420,6 +421,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
420421
LONG_VERSION_PY[
421422
"git"
422423
] = r'''
424+
# pylint: disable=consider-using-f-string
423425
# This file helps to compute a version number in source trees obtained from
424426
# git-archive tarball (such as those provided by GitHub's download-from-tag
425427
# feature). Distribution tarballs (built by setup.py sdist) and build

0 commit comments

Comments
 (0)