diff --git a/pandas/tests/util/test_validate_args.py b/pandas/tests/util/test_validate_args.py index dfbd8a3f9af19..746d859b3322e 100644 --- a/pandas/tests/util/test_validate_args.py +++ b/pandas/tests/util/test_validate_args.py @@ -20,10 +20,8 @@ def test_bad_arg_length_max_value_single(): max_length = len(compat_args) + min_fname_arg_count actual_length = len(args) + min_fname_arg_count msg = ( - r"{fname}\(\) takes at most {max_length} " - r"argument \({actual_length} given\)".format( - fname=_fname, max_length=max_length, actual_length=actual_length - ) + fr"{_fname}\(\) takes at most {max_length} " + fr"argument \({actual_length} given\)" ) with pytest.raises(TypeError, match=msg): @@ -38,10 +36,8 @@ def test_bad_arg_length_max_value_multiple(): max_length = len(compat_args) + min_fname_arg_count actual_length = len(args) + min_fname_arg_count msg = ( - r"{fname}\(\) takes at most {max_length} " - r"arguments \({actual_length} given\)".format( - fname=_fname, max_length=max_length, actual_length=actual_length - ) + fr"{_fname}\(\) takes at most {max_length} " + fr"arguments \({actual_length} given\)" ) with pytest.raises(TypeError, match=msg): @@ -52,8 +48,8 @@ def test_bad_arg_length_max_value_multiple(): def test_not_all_defaults(i): bad_arg = "foo" msg = ( - "the '{arg}' parameter is not supported " - r"in the pandas implementation of {func}\(\)".format(arg=bad_arg, func=_fname) + f"the '{bad_arg}' parameter is not supported " + fr"in the pandas implementation of {_fname}\(\)" ) compat_args = {"foo": 2, "bar": -1, "baz": 3} diff --git a/pandas/tests/util/test_validate_kwargs.py b/pandas/tests/util/test_validate_kwargs.py index a26d96fcda231..a7b6d8f98cc60 100644 --- a/pandas/tests/util/test_validate_kwargs.py +++ b/pandas/tests/util/test_validate_kwargs.py @@ -22,8 +22,8 @@ def test_bad_kwarg(): def test_not_all_none(i): bad_arg = "foo" msg = ( - r"the '{arg}' parameter is not supported " - r"in the pandas implementation of {func}\(\)".format(arg=bad_arg, func=_fname) + fr"the '{bad_arg}' parameter is not supported " + fr"in the pandas implementation of {_fname}\(\)" ) compat_args = {"foo": 1, "bar": "s", "baz": None} diff --git a/pandas/tests/window/test_window.py b/pandas/tests/window/test_window.py index 39ab3ffd9319e..cc29ab4f2cd62 100644 --- a/pandas/tests/window/test_window.py +++ b/pandas/tests/window/test_window.py @@ -65,7 +65,7 @@ def test_agg_function_support(self, arg): df = pd.DataFrame({"A": np.arange(5)}) roll = df.rolling(2, win_type="triang") - msg = "'{arg}' is not a valid function for 'Window' object".format(arg=arg) + msg = f"'{arg}' is not a valid function for 'Window' object" with pytest.raises(AttributeError, match=msg): roll.agg(arg) diff --git a/pandas/tseries/holiday.py b/pandas/tseries/holiday.py index 2e5477ea00e39..62d7c26b590cc 100644 --- a/pandas/tseries/holiday.py +++ b/pandas/tseries/holiday.py @@ -186,16 +186,16 @@ class from pandas.tseries.offsets def __repr__(self) -> str: info = "" if self.year is not None: - info += "year={year}, ".format(year=self.year) - info += "month={mon}, day={day}, ".format(mon=self.month, day=self.day) + info += f"year={self.year}, " + info += f"month={self.month}, day={self.day}, " if self.offset is not None: - info += "offset={offset}".format(offset=self.offset) + info += f"offset={self.offset}" if self.observance is not None: - info += "observance={obs}".format(obs=self.observance) + info += f"observance={self.observance}" - repr = "Holiday: {name} ({info})".format(name=self.name, info=info) + repr = f"Holiday: {self.name} ({info})" return repr def dates(self, start_date, end_date, return_name=False): @@ -394,8 +394,7 @@ def holidays(self, start=None, end=None, return_name=False): """ if self.rules is None: raise Exception( - "Holiday Calendar {name} does not have any " - "rules specified".format(name=self.name) + f"Holiday Calendar {self.name} does not have any rules specified" ) if start is None: diff --git a/scripts/download_wheels.py b/scripts/download_wheels.py index 4ca1354321134..3d36eed2d888a 100644 --- a/scripts/download_wheels.py +++ b/scripts/download_wheels.py @@ -26,7 +26,7 @@ def fetch(version): files = [ x for x in root.xpath("//a/text()") - if x.startswith("pandas-{}".format(version)) and not dest.joinpath(x).exists() + if x.startswith(f"pandas-{version}") and not dest.joinpath(x).exists() ] N = len(files) @@ -35,9 +35,7 @@ def fetch(version): out = str(dest.joinpath(filename)) link = urllib.request.urljoin(base, filename) urllib.request.urlretrieve(link, out) - print( - "Downloaded {link} to {out} [{i}/{N}]".format(link=link, out=out, i=i, N=N) - ) + print(f"Downloaded {link} to {out} [{i}/{N}]") def main(args=None): diff --git a/scripts/generate_pip_deps_from_conda.py b/scripts/generate_pip_deps_from_conda.py index 1d2c33aeee384..3b14d61ce4254 100755 --- a/scripts/generate_pip_deps_from_conda.py +++ b/scripts/generate_pip_deps_from_conda.py @@ -127,13 +127,13 @@ def main(conda_fname, pip_fname, compare=False): ) if res: msg = ( - "`requirements-dev.txt` has to be generated with `{}` after " - "`environment.yml` is modified.\n".format(sys.argv[0]) + f"`requirements-dev.txt` has to be generated with `{sys.argv[0]}` after " + "`environment.yml` is modified.\n" ) if args.azure: msg = ( "##vso[task.logissue type=error;" - "sourcepath=requirements-dev.txt]{}".format(msg) + f"sourcepath=requirements-dev.txt]{msg}" ) sys.stderr.write(msg) sys.exit(res) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 674e3b72884fa..a1bccb1dd1629 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -1300,7 +1300,7 @@ def test_resolves_class_name(self, name, expected_obj): @pytest.mark.parametrize("invalid_name", ["panda", "panda.DataFrame"]) def test_raises_for_invalid_module_name(self, invalid_name): - msg = 'No module can be imported from "{}"'.format(invalid_name) + msg = f'No module can be imported from "{invalid_name}"' with pytest.raises(ImportError, match=msg): validate_docstrings.Docstring(invalid_name) @@ -1310,7 +1310,7 @@ def test_raises_for_invalid_module_name(self, invalid_name): def test_raises_for_invalid_attribute_name(self, invalid_name): name_components = invalid_name.split(".") obj_name, invalid_attr_name = name_components[-2], name_components[-1] - msg = "'{}' has no attribute '{}'".format(obj_name, invalid_attr_name) + msg = f"'{obj_name}' has no attribute '{invalid_attr_name}'" with pytest.raises(AttributeError, match=msg): validate_docstrings.Docstring(invalid_name) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 872182ee8e20f..bcf3fd5d276f5 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -357,7 +357,7 @@ def source_file_def_line(self): @property def github_url(self): url = "https://github.com/pandas-dev/pandas/blob/master/" - url += "{}#L{}".format(self.source_file_name, self.source_file_def_line) + url += f"{self.source_file_name}#L{self.source_file_def_line}" return url @property @@ -501,7 +501,7 @@ def parameter_desc(self, param): desc = self.doc_parameters[param][1] # Find and strip out any sphinx directives for directive in DIRECTIVES: - full_directive = ".. {}".format(directive) + full_directive = f".. {directive}" if full_directive in desc: # Only retain any description before the directive desc = desc[: desc.index(full_directive)] @@ -825,14 +825,12 @@ def get_validation_data(doc): "EX03", error_code=err.error_code, error_message=err.message, - times_happening=" ({} times)".format(err.count) - if err.count > 1 - else "", + times_happening=f" ({err.count} times)" if err.count > 1 else "", ) ) examples_source_code = "".join(doc.examples_source_code) for wrong_import in ("numpy", "pandas"): - if "import {}".format(wrong_import) in examples_source_code: + if f"import {wrong_import}" in examples_source_code: errs.append(error("EX04", imported_library=wrong_import)) return errs, wrns, examples_errs @@ -920,7 +918,7 @@ def validate_all(prefix, ignore_deprecated=False): api_item_names = set(list(zip(*api_items))[0]) for class_ in (pandas.Series, pandas.DataFrame): for member in inspect.getmembers(class_): - func_name = "pandas.{}.{}".format(class_.__name__, member[0]) + func_name = f"pandas.{class_.__name__}.{member[0]}" if not member[0].startswith("_") and func_name not in api_item_names: if prefix and not func_name.startswith(prefix): continue @@ -938,13 +936,9 @@ def header(title, width=80, char="#"): full_line = char * width side_len = (width - len(title) - 2) // 2 adj = "" if len(title) % 2 == 0 else " " - title_line = "{side} {title}{adj} {side}".format( - side=char * side_len, title=title, adj=adj - ) + title_line = f"{char * side_len} {title}{adj} {char * side_len}" - return "\n{full_line}\n{title_line}\n{full_line}\n\n".format( - full_line=full_line, title_line=title_line - ) + return f"\n{full_line}\n{title_line}\n{full_line}\n\n" exit_status = 0 if func_name is None: @@ -986,24 +980,24 @@ def header(title, width=80, char="#"): else: result = validate_one(func_name) - sys.stderr.write(header("Docstring ({})".format(func_name))) - sys.stderr.write("{}\n".format(result["docstring"])) + sys.stderr.write(header(f"Docstring ({func_name})")) + sys.stderr.write(f"{result['docstring']}\n") sys.stderr.write(header("Validation")) if result["errors"]: - sys.stderr.write("{} Errors found:\n".format(len(result["errors"]))) + sys.stderr.write(f"{len(result['errors'])} Errors found:\n") for err_code, err_desc in result["errors"]: # Failing examples are printed at the end if err_code == "EX02": sys.stderr.write("\tExamples do not pass tests\n") continue - sys.stderr.write("\t{}\n".format(err_desc)) + sys.stderr.write(f"\t{err_desc}\n") if result["warnings"]: - sys.stderr.write("{} Warnings found:\n".format(len(result["warnings"]))) + sys.stderr.write(f"{len(result['warnings'])} Warnings found:\n") for wrn_code, wrn_desc in result["warnings"]: - sys.stderr.write("\t{}\n".format(wrn_desc)) + sys.stderr.write(f"\t{wrn_desc}\n") if not result["errors"]: - sys.stderr.write('Docstring for "{}" correct. :)\n'.format(func_name)) + sys.stderr.write(f'Docstring for "{func_name}" correct. :)\n') if result["examples_errors"]: sys.stderr.write(header("Doctests")) @@ -1027,7 +1021,7 @@ def header(title, width=80, char="#"): choices=format_opts, help="format of the output when validating " "multiple docstrings (ignored when validating one)." - "It can be {}".format(str(format_opts)[1:-1]), + f"It can be {str(format_opts)[1:-1]}", ) argparser.add_argument( "--prefix",