From 9ff401ca0996e318d04f084defe88d49548f303e Mon Sep 17 00:00:00 2001 From: Kyle McCahill Date: Mon, 16 Dec 2019 16:57:35 -0600 Subject: [PATCH 1/3] f-str formatting --- pandas/_config/config.py | 10 ++++++---- pandas/_config/localization.py | 2 +- setup.py | 20 ++++++++------------ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 8f75d0381c1a6..7d9827ec6b370 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -461,16 +461,17 @@ def register_option(key: str, defval: object, doc="", validator=None, cb=None): raise ValueError(f"{k} is a python keyword") cursor = _global_config - msg = "Path prefix to option '{option}' is already an option" for i, p in enumerate(path[:-1]): if not isinstance(cursor, dict): - raise OptionError(msg.format(option=".".join(path[:i]))) + option = ".".join(path[:i]) + raise OptionError(f"Path prefix to option '{option}' is already an option") if p not in cursor: cursor[p] = {} cursor = cursor[p] if not isinstance(cursor, dict): - raise OptionError(msg.format(option=".".join(path[:-1]))) + option = ".".join(path[:-1]) + raise OptionError(f"Path prefix to option '{option}' is already an option") cursor[path[-1]] = defval # initialize @@ -650,8 +651,9 @@ def _build_option_description(k): s += f"\n [default: {o.defval}] [currently: {_get_option(k, True)}]" if d: + rkey = d.rkey if d.rkey else "" s += "\n (Deprecated" - s += ", use `{rkey}` instead.".format(rkey=d.rkey if d.rkey else "") + s += f", use `{rkey}` instead." s += ")" return s diff --git a/pandas/_config/localization.py b/pandas/_config/localization.py index ba60b1e003004..dd1d4948aa6e3 100644 --- a/pandas/_config/localization.py +++ b/pandas/_config/localization.py @@ -161,6 +161,6 @@ def get_locales(prefix=None, normalize=True, locale_getter=_default_locale_gette if prefix is None: return _valid_locales(out_locales, normalize) - pattern = re.compile("{prefix}.*".format(prefix=prefix)) + pattern = re.compile(f"{prefix}.*") found = pattern.findall("\n".join(out_locales)) return _valid_locales(found, normalize) diff --git a/setup.py b/setup.py index e42a570200dc3..38fc57e4f80bf 100755 --- a/setup.py +++ b/setup.py @@ -39,9 +39,9 @@ def is_platform_mac(): "install_requires": [ "python-dateutil >= 2.6.1", "pytz >= 2017.2", - "numpy >= {numpy_ver}".format(numpy_ver=min_numpy_ver), + f"numpy >= {min_numpy_ver}", ], - "setup_requires": ["numpy >= {numpy_ver}".format(numpy_ver=min_numpy_ver)], + "setup_requires": [f"numpy >= {min_numpy_ver}"], "zip_safe": False, } @@ -364,10 +364,8 @@ def run(self): for pyxfile in pyxfiles: sourcefile = pyxfile[:-3] + extension msg = ( - "{extension}-source file '{source}' not found.\n" - "Run 'setup.py cython' before sdist.".format( - source=sourcefile, extension=extension - ) + f"{extension}-source file '{sourcefile}' not found.\n" + f"Run 'setup.py cython' before sdist." ) assert os.path.isfile(sourcefile), msg sdist_class.run(self) @@ -382,14 +380,12 @@ def check_cython_extensions(self, extensions): for ext in extensions: for src in ext.sources: if not os.path.exists(src): - print("{}: -> [{}]".format(ext.name, ext.sources)) + print(f"{ext.name}: -> [{ext.sources}]") raise Exception( - """Cython-generated file '{src}' not found. + f"""Cython-generated file '{src}' not found. Cython is required to compile pandas from a development branch. Please install Cython or download a release package of pandas. - """.format( - src=src - ) + """ ) def build_extensions(self): @@ -706,7 +702,7 @@ def srcpath(name=None, suffix=".pyx", subdir="src"): include = data.get("include") obj = Extension( - "pandas.{name}".format(name=name), + f"pandas.{name}", sources=sources, depends=data.get("depends", []), include_dirs=include, From 702598a0cb62a92248efefcc28e2e089dd6b9e29 Mon Sep 17 00:00:00 2001 From: Kyle McCahill Date: Mon, 16 Dec 2019 18:20:04 -0600 Subject: [PATCH 2/3] chged back to .format --- pandas/_config/config.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 7d9827ec6b370..a274430e29e5d 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -388,7 +388,7 @@ class option_context: Examples -------- - >>> with option_context('display.max_rows', 10, 'display.max_columns', 5): + with option_context('display.max_rows', 10, 'display.max_columns', 5): ... ... """ @@ -461,17 +461,17 @@ def register_option(key: str, defval: object, doc="", validator=None, cb=None): raise ValueError(f"{k} is a python keyword") cursor = _global_config + msg = "Path prefix to option '{option}' is already an option" + for i, p in enumerate(path[:-1]): if not isinstance(cursor, dict): - option = ".".join(path[:i]) - raise OptionError(f"Path prefix to option '{option}' is already an option") + raise OptionError(msg.format(option=".".join(path[:i]))) if p not in cursor: cursor[p] = {} cursor = cursor[p] if not isinstance(cursor, dict): - option = ".".join(path[:-1]) - raise OptionError(f"Path prefix to option '{option}' is already an option") + raise OptionError(msg.format(option=".".join(path[:-1]))) cursor[path[-1]] = defval # initialize From a186ddf6d8d7be4457c20aa689802436f438a5fa Mon Sep 17 00:00:00 2001 From: Kyle McCahill Date: Mon, 16 Dec 2019 19:22:47 -0600 Subject: [PATCH 3/3] Update config.py --- pandas/_config/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index a274430e29e5d..9e74eb46f7b1f 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -388,7 +388,7 @@ class option_context: Examples -------- - with option_context('display.max_rows', 10, 'display.max_columns', 5): + >>> with option_context('display.max_rows', 10, 'display.max_columns', 5): ... ... """