Skip to content

STYLE: fix pylint consider-using-f-string issues #49515

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

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def setup(self):
np.random.randn(N, 100), index=date_range("1/1/2000", periods=N)
)
self.df_dc = DataFrame(
np.random.randn(N, 10), columns=["C%03d" % i for i in range(10)]
np.random.randn(N, 10), columns=[f"C{i:03d}" for i in range(10)]
)

self.fname = "__test__.h5"
Expand Down
6 changes: 3 additions & 3 deletions doc/scripts/eval_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def bench_with(n, times=10, repeat=3, engine="numexpr"):
return (
np.array(
timeit(
"df.eval(s, engine=%r)" % engine,
f"df.eval(s, engine={repr(engine)})",
setup=setup_common % (n, setup_with),
repeat=repeat,
number=times,
Expand All @@ -34,7 +34,7 @@ def bench_subset(n, times=20, repeat=3, engine="numexpr"):
return (
np.array(
timeit(
"df.query(s, engine=%r)" % engine,
f"df.query(s, engine={repr(engine)})",
setup=setup_common % (n, setup_subset),
repeat=repeat,
number=times,
Expand All @@ -55,7 +55,7 @@ def bench(mn=3, mx=7, num=100, engines=("python", "numexpr"), verbose=False):
for engine in engines:
for i, n in enumerate(r):
if verbose & (i % 10 == 0):
print("engine: %r, i == %d" % (engine, i))
print(f"engine: {repr(engine)}, i == {i:d}")
ev_times = bench_with(n, times=1, repeat=1, engine=engine)
ev.loc[i, engine] = np.mean(ev_times)
qu_times = bench_subset(n, times=1, repeat=1, engine=engine)
Expand Down
1 change: 1 addition & 0 deletions pandas/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=consider-using-f-string
# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by GitHub's download-from-tag
# feature). Distribution tarballs (built by setup.py sdist) and build
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/arraylike.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ def array_ufunc(self, ufunc: np.ufunc, method: str, *inputs: Any, **kwargs: Any)
# well. Previously this raised an internal ValueError. We might
# support it someday, so raise a NotImplementedError.
raise NotImplementedError(
"Cannot apply ufunc {} to mixed DataFrame and Series "
"inputs.".format(ufunc)
f"Cannot apply ufunc {ufunc} to mixed DataFrame and Series inputs."
)
axes = self.axes
for obj in alignable[1:]:
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import collections
from datetime import timedelta
import functools
import gc
import json
import operator
Expand Down Expand Up @@ -4596,7 +4595,7 @@ def add_prefix(self: NDFrameT, prefix: str, axis: Axis | None = None) -> NDFrame
2 3 5
3 4 6
"""
f = functools.partial("{prefix}{}".format, prefix=prefix)
f = lambda x: f"{prefix}{x}"

axis_name = self._info_axis_name
if axis is not None:
Expand Down Expand Up @@ -4670,7 +4669,7 @@ def add_suffix(self: NDFrameT, suffix: str, axis: Axis | None = None) -> NDFrame
2 3 5
3 4 6
"""
f = functools.partial("{}{suffix}".format, suffix=suffix)
f = lambda x: f"{x}{suffix}"

axis_name = self._info_axis_name
if axis is not None:
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def test_validation(self):

validator = cf.is_one_of_factory([None, cf.is_callable])
cf.register_option("b", lambda: None, "doc", validator=validator)
# pylint: disable-next=consider-using-f-string
cf.set_option("b", "%.1f".format) # Formatter is callable
cf.set_option("b", None) # Formatter is none (default)
with pytest.raises(ValueError, match="Value must be a callable"):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def run_tests(df, rhs, right_loc, right_iloc):
# make frames multi-type & re-run tests
for frame in [df, rhs, right_loc, right_iloc]:
frame["joe"] = frame["joe"].astype("float64")
frame["jolie"] = frame["jolie"].map("@{}".format)
frame["jolie"] = frame["jolie"].map(lambda x: f"@{x}")
right_iloc["joe"] = [1.0, "@-28", "@-20", "@-12", 17.0]
right_iloc["jolie"] = ["@2", -26.0, -18.0, -10.0, "@18"]
run_tests(df, rhs, right_loc, right_iloc)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/excel/test_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_to_excel_with_openpyxl_engine(ext):
df2 = DataFrame({"B": np.linspace(1, 20, 10)})
df = pd.concat([df1, df2], axis=1)
styled = df.style.applymap(
lambda val: "color: %s" % ("red" if val < 0 else "black")
lambda val: f"color: {'red' if val < 0 else 'black'}"
).highlight_max()

styled.to_excel(filename, engine="openpyxl")
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/io/formats/style/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,14 +802,15 @@ def test_rendered_links(type, text, exp, found):
df = DataFrame([0], index=[text])
styler = df.style.format_index(hyperlinks="html")

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


def test_multiple_rendered_links():
links = ("www.a.b", "http://a.c", "https://a.d", "ftp://a.e")
# pylint: disable-next=consider-using-f-string
df = DataFrame(["text {} {} text {} {}".format(*links)])
result = df.style.format(hyperlinks="html").to_html()
href = '<a href="{0}" target="_blank">{0}</a>'
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ def test_to_latex_multiindex_names(self, name0, name1, axes):
placeholder = "{}" if any(names) and 1 in axes else " "
col_names = [n if (bool(n) and 1 in axes) else placeholder for n in names]
observed = df.to_latex()
# pylint: disable-next=consider-using-f-string
expected = r"""\begin{tabular}{llrrrr}
\toprule
& %s & \multicolumn{2}{l}{1} & \multicolumn{2}{l}{2} \\
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def test_from_s3_csv(s3_resource, tips_file, s3so):
@td.skip_if_no("s3fs")
def test_s3_protocols(s3_resource, tips_file, protocol, s3so):
tm.assert_equal(
read_csv("%s://pandas-test/tips.csv" % protocol, storage_options=s3so),
read_csv(f"{protocol}://pandas-test/tips.csv", storage_options=s3so),
read_csv(tips_file),
)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def test_to_html_compat(self):
c_idx_names=False,
r_idx_names=False,
)
.applymap("{:.3f}".format)
.astype(float)
# pylint: disable-next=consider-using-f-string
.applymap("{:.3f}".format).astype(float)
)
out = df.to_html()
res = self.read_html(out, attrs={"class": "dataframe"}, index_col=0)[0]
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ disable = [
"used-before-assignment",

# pylint type "C": convention, for programming standard violation
"consider-using-f-string",
"import-outside-toplevel",
"invalid-name",
"line-too-long",
Expand Down
2 changes: 2 additions & 0 deletions versioneer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Version: 0.19
# pylint: disable=consider-using-f-string

"""The Versioneer - like a rocketeer, but for versions.

Expand Down Expand Up @@ -420,6 +421,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
LONG_VERSION_PY[
"git"
] = r'''
# pylint: disable=consider-using-f-string
# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by GitHub's download-from-tag
# feature). Distribution tarballs (built by setup.py sdist) and build
Expand Down