From 1f39630c96dda0b6da15f64f5734ef0f15441bd4 Mon Sep 17 00:00:00 2001 From: Paul Lee Date: Sun, 29 Dec 2019 13:23:01 -0500 Subject: [PATCH 1/5] CLN: Update old string formatting to f-strings Reviewed and updated to f-string for: pandas/compat/pickle_compat.py pandas/_config/config.py pandas/core/arrays/boolean.py Contributes to GH29547 --- pandas/_config/config.py | 5 ++--- pandas/core/arrays/boolean.py | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 6844df495547a..b58899fdf8eae 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -461,17 +461,16 @@ 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]))) + raise OptionError(f"Path prefix to option '{'.'.join(path[:i])}' 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]))) + raise OptionError(f"Path prefix to option '{'.'.join(path[:-1])}' is already an option") cursor[path[-1]] = defval # initialize diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index a8fcd6d03847c..b85ff117034a0 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -755,9 +755,7 @@ def logical_method(self, other): if other_is_scalar and not (other is libmissing.NA or lib.is_bool(other)): raise TypeError( - "'other' should be pandas.NA or a bool. Got {} instead.".format( - type(other).__name__ - ) + f"'other' should be pandas.NA or a bool. Got {type(other).__name__} instead." ) if not other_is_scalar and len(self) != len(other): @@ -772,7 +770,7 @@ def logical_method(self, other): return BooleanArray(result, mask) - name = "__{name}__".format(name=op.__name__) + name = f"__{op.__name__}__" return set_function_name(logical_method, name, cls) @classmethod @@ -819,7 +817,7 @@ def cmp_method(self, other): return BooleanArray(result, mask, copy=False) - name = "__{name}__".format(name=op.__name__) + name = f"__{op.__name__}" return set_function_name(cmp_method, name, cls) def _reduce(self, name, skipna=True, **kwargs): @@ -922,7 +920,7 @@ def boolean_arithmetic_method(self, other): return self._maybe_mask_result(result, mask, other, op_name) - name = "__{name}__".format(name=op_name) + name = f"__{op_name}__" return set_function_name(boolean_arithmetic_method, name, cls) From fda9c0a6462e734936e4dc977dacb2e09227886c Mon Sep 17 00:00:00 2001 From: Paul Lee Date: Sun, 29 Dec 2019 13:47:40 -0500 Subject: [PATCH 2/5] ran black pandas --- pandas/_config/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index b58899fdf8eae..db6386465762c 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -464,13 +464,17 @@ def register_option(key: str, defval: object, doc="", validator=None, cb=None): for i, p in enumerate(path[:-1]): if not isinstance(cursor, dict): - raise OptionError(f"Path prefix to option '{'.'.join(path[:i])}' is already an option") + raise OptionError( + f"Path prefix to option '{'.'.join(path[:i])}' is already an option" + ) if p not in cursor: cursor[p] = {} cursor = cursor[p] if not isinstance(cursor, dict): - raise OptionError(f"Path prefix to option '{'.'.join(path[:-1])}' is already an option") + raise OptionError( + f"Path prefix to option '{'.'.join(path[:-1])}' is already an option" + ) cursor[path[-1]] = defval # initialize From 989e389c71f1b0bc8c1fd02f0cf7e03b14e85f75 Mon Sep 17 00:00:00 2001 From: Paul Lee Date: Sun, 29 Dec 2019 15:36:19 -0500 Subject: [PATCH 3/5] Styling fixes --- pandas/core/arrays/boolean.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index b85ff117034a0..456df0f4eca19 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -755,7 +755,8 @@ def logical_method(self, other): if other_is_scalar and not (other is libmissing.NA or lib.is_bool(other)): raise TypeError( - f"'other' should be pandas.NA or a bool. Got {type(other).__name__} instead." + f"'other' should be pandas.NA or a bool.\ + Got {type(other).__name__} instead." ) if not other_is_scalar and len(self) != len(other): From a216bef63f5992b4d0aeee4a267d1bf2e72da6da Mon Sep 17 00:00:00 2001 From: Paul Lee Date: Sun, 29 Dec 2019 19:35:37 -0500 Subject: [PATCH 4/5] Go back to .format syntax --- pandas/_config/config.py | 9 +++------ pandas/core/arrays/boolean.py | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pandas/_config/config.py b/pandas/_config/config.py index db6386465762c..6844df495547a 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -461,20 +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( - f"Path prefix to option '{'.'.join(path[:i])}' 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): - raise OptionError( - f"Path prefix to option '{'.'.join(path[:-1])}' is already an option" - ) + raise OptionError(msg.format(option=".".join(path[:-1]))) cursor[path[-1]] = defval # initialize diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 456df0f4eca19..7bd409cd7b423 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -755,8 +755,8 @@ def logical_method(self, other): if other_is_scalar and not (other is libmissing.NA or lib.is_bool(other)): raise TypeError( - f"'other' should be pandas.NA or a bool.\ - Got {type(other).__name__} instead." + f"'other' should be pandas.NA or a bool. " + f"Got {type(other).__name__} instead." ) if not other_is_scalar and len(self) != len(other): From b6f4e641de7cc3ddb77813404eba0d74875c62c4 Mon Sep 17 00:00:00 2001 From: Paul Lee Date: Sun, 29 Dec 2019 20:04:48 -0500 Subject: [PATCH 5/5] Update pandas/core/arrays/boolean.py Co-Authored-By: Marc Garcia --- pandas/core/arrays/boolean.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 7bd409cd7b423..b030a9a9cf139 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -755,7 +755,7 @@ def logical_method(self, other): if other_is_scalar and not (other is libmissing.NA or lib.is_bool(other)): raise TypeError( - f"'other' should be pandas.NA or a bool. " + "'other' should be pandas.NA or a bool. " f"Got {type(other).__name__} instead." )