diff --git a/asv_bench/benchmarks/io/hdf.py b/asv_bench/benchmarks/io/hdf.py index 4a2c1c872e6eb..12bc65f9e7bf5 100644 --- a/asv_bench/benchmarks/io/hdf.py +++ b/asv_bench/benchmarks/io/hdf.py @@ -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" diff --git a/doc/scripts/eval_performance.py b/doc/scripts/eval_performance.py index 27d9bf23fc1af..85d9ce4ad01e9 100644 --- a/doc/scripts/eval_performance.py +++ b/doc/scripts/eval_performance.py @@ -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, @@ -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, @@ -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) diff --git a/pandas/_version.py b/pandas/_version.py index 25142781299b4..89a3caaf64eae 100644 --- a/pandas/_version.py +++ b/pandas/_version.py @@ -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 diff --git a/pandas/core/arraylike.py b/pandas/core/arraylike.py index 383ee2c53f0ae..c891ac2fcfc51 100644 --- a/pandas/core/arraylike.py +++ b/pandas/core/arraylike.py @@ -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:]: diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f88fe35360074..c8f30c12d321f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3,7 +3,6 @@ import collections from datetime import timedelta -import functools import gc import json import operator @@ -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: @@ -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: diff --git a/pandas/tests/config/test_config.py b/pandas/tests/config/test_config.py index 005fd902afc0e..8a2d53313702d 100644 --- a/pandas/tests/config/test_config.py +++ b/pandas/tests/config/test_config.py @@ -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"): diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 0502fd445e66e..b3e59da4b0130 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -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) diff --git a/pandas/tests/io/excel/test_openpyxl.py b/pandas/tests/io/excel/test_openpyxl.py index 7351629660cee..be0428a2b0fce 100644 --- a/pandas/tests/io/excel/test_openpyxl.py +++ b/pandas/tests/io/excel/test_openpyxl.py @@ -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") diff --git a/pandas/tests/io/formats/style/test_html.py b/pandas/tests/io/formats/style/test_html.py index 46891863975ea..43eb4cb0502a1 100644 --- a/pandas/tests/io/formats/style/test_html.py +++ b/pandas/tests/io/formats/style/test_html.py @@ -802,7 +802,7 @@ def test_rendered_links(type, text, exp, found): df = DataFrame([0], index=[text]) styler = df.style.format_index(hyperlinks="html") - rendered = '{0}'.format(found) + rendered = f'{found}' result = styler.to_html() assert (rendered in result) is exp assert (text in result) is not exp # test conversion done when expected and not @@ -810,6 +810,7 @@ def test_rendered_links(type, text, exp, found): 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 = '{0}' diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index f8015851c9a83..11ee41ed40ce8 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -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} \\ diff --git a/pandas/tests/io/test_fsspec.py b/pandas/tests/io/test_fsspec.py index bdd4cd95ec1af..a1c597087788c 100644 --- a/pandas/tests/io/test_fsspec.py +++ b/pandas/tests/io/test_fsspec.py @@ -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), ) diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 1f3f8e3b4cbca..daa2dffeaa143 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -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] diff --git a/pyproject.toml b/pyproject.toml index 2e2e3fd914c86..f9fd65a63b26a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/versioneer.py b/versioneer.py index 2ab269f9c3ea8..1ff2e936e15cc 100644 --- a/versioneer.py +++ b/versioneer.py @@ -1,4 +1,5 @@ # Version: 0.19 +# pylint: disable=consider-using-f-string """The Versioneer - like a rocketeer, but for versions. @@ -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