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..4d6f05769415c 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -1933,10 +1933,9 @@ 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 " - "{inf_type!r}.".format( - name=func_name, inf_type=self._inferred_dtype - ) + 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)