From b1ef57be61b5d3cb27b7dbbb736b590829cf6bdf Mon Sep 17 00:00:00 2001 From: sourav kumar Date: Tue, 3 Dec 2019 21:55:49 +0530 Subject: [PATCH 1/3] changed "fun !r" -> "repr(fun)" As described in the following issue https://github.com/pandas-dev/pandas/issues/29886 , usage of !r is currently redundant and so changing to f strings in place of it. --- pandas/core/series.py | 2 +- pandas/core/sorting.py | 4 ++-- pandas/core/strings.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 11e87a4eed27f..302d4b591fc1e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2944,7 +2944,7 @@ def _try_kind_sort(arr): sortedIdx[n:] = idx[good][argsorted] sortedIdx[:n] = idx[bad] else: - raise ValueError("invalid na_position: {!r}".format(na_position)) + raise ValueError(f"invalid na_position: {repr(na_position)}") result = self._constructor(arr[sortedIdx], index=self.index[sortedIdx]) diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index 82eb93dd4c879..ed9ef23132683 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -208,7 +208,7 @@ def lexsort_indexer(keys, orders=None, na_position="last"): cat = Categorical(key, ordered=True) if na_position not in ["last", "first"]: - raise ValueError("invalid na_position: {!r}".format(na_position)) + raise ValueError(f"invalid na_position: {repr(na_position)}") n = len(cat.categories) codes = cat.codes.copy() @@ -264,7 +264,7 @@ def nargsort(items, kind="quicksort", ascending: bool = True, na_position="last" elif na_position == "first": indexer = np.concatenate([nan_idx, indexer]) else: - raise ValueError("invalid na_position: {!r}".format(na_position)) + raise ValueError(f"invalid na_position: {repr(na_position)}") return indexer diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 137c37f938dfa..f085017ea88cd 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1934,8 +1934,8 @@ def wrapper(self, *args, **kwargs): if self._inferred_dtype not in allowed_types: msg = ( "Cannot use .str.{name} with values of inferred dtype " - "{inf_type!r}.".format( - name=func_name, inf_type=self._inferred_dtype + f"{repr(self._inferred_dtype)}.".format( + name=func_name ) ) raise TypeError(msg) From ea892288fcf2786f15992569aadc736e389bcf52 Mon Sep 17 00:00:00 2001 From: Sourav kumar <33771969+souravs17031999@users.noreply.github.com> Date: Wed, 4 Dec 2019 07:43:36 +0530 Subject: [PATCH 2/3] update in the line 1936 by using func_name and removing .format As indicated i have removed .format --- pandas/core/strings.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index f085017ea88cd..dc03096e8a795 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1933,9 +1933,8 @@ def _forbid_nonstring_types(func): def wrapper(self, *args, **kwargs): if self._inferred_dtype not in allowed_types: msg = ( - "Cannot use .str.{name} with values of inferred dtype " - f"{repr(self._inferred_dtype)}.".format( - name=func_name + f"Cannot use .str.{repr(func_name)} with values of inferred dtype " + f"{repr(self._inferred_dtype)}." ) ) raise TypeError(msg) From fc5135ef32e3118dd90cf783574ee792939d38e8 Mon Sep 17 00:00:00 2001 From: Sourav kumar <33771969+souravs17031999@users.noreply.github.com> Date: Wed, 4 Dec 2019 08:24:48 +0530 Subject: [PATCH 3/3] removing extra ')' --- pandas/core/strings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index dc03096e8a795..4d6f05769415c 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1935,7 +1935,7 @@ def wrapper(self, *args, **kwargs): msg = ( f"Cannot use .str.{repr(func_name)} with values of inferred dtype " f"{repr(self._inferred_dtype)}." - ) + ) raise TypeError(msg) return func(self, *args, **kwargs)