From a5591b28c3a7ec4f025359ffba3aa9149d4fdc99 Mon Sep 17 00:00:00 2001 From: Darin Plutchok Date: Tue, 3 Dec 2019 15:35:07 -0800 Subject: [PATCH] f-string update for core.base. --- pandas/core/base.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/pandas/core/base.py b/pandas/core/base.py index 066a7628be364..5e613849ba8d5 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -114,9 +114,7 @@ def __setattr__(self, key, value): or key in type(self).__dict__ or getattr(self, key, None) is not None ): - raise AttributeError( - "You cannot add any new attribute '{key}'".format(key=key) - ) + raise AttributeError(f"You cannot add any new attribute '{key}'") object.__setattr__(self, key, value) @@ -220,28 +218,22 @@ def _obj_with_exclusions(self): def __getitem__(self, key): if self._selection is not None: - raise IndexError( - "Column(s) {selection} already selected".format( - selection=self._selection - ) - ) + raise IndexError(f"Column(s) {self._selection} already selected") if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray)): if len(self.obj.columns.intersection(key)) != len(key): bad_keys = list(set(key).difference(self.obj.columns)) - raise KeyError( - "Columns not found: {missing}".format(missing=str(bad_keys)[1:-1]) - ) + raise KeyError(f"Columns not found: {str(bad_keys)[1:-1]}") return self._gotitem(list(key), ndim=2) elif not getattr(self, "as_index", False): if key not in self.obj.columns: - raise KeyError("Column not found: {key}".format(key=key)) + raise KeyError(f"Column not found: {key}") return self._gotitem(key, ndim=2) else: if key not in self.obj: - raise KeyError("Column not found: {key}".format(key=key)) + raise KeyError(f"Column not found: {key}") return self._gotitem(key, ndim=1) def _gotitem(self, key, ndim, subset=None): @@ -293,8 +285,7 @@ def _try_aggregate_string_function(self, arg: str, *args, **kwargs): return f(self, *args, **kwargs) raise AttributeError( - "'{arg}' is not a valid function for " - "'{cls}' object".format(arg=arg, cls=type(self).__name__) + f"'{arg}' is not a valid function for '{type(self).__name__}' object" ) def _aggregate(self, arg, *args, **kwargs): @@ -359,7 +350,7 @@ def _aggregate(self, arg, *args, **kwargs): elif isinstance(obj, ABCSeries): raise SpecificationError("nested renamer is not supported") elif isinstance(obj, ABCDataFrame) and k not in obj.columns: - raise KeyError("Column '{col}' does not exist!".format(col=k)) + raise KeyError(f"Column '{k}' does not exist!") arg = new_arg @@ -1101,9 +1092,7 @@ def _reduce( func = getattr(self, name, None) if func is None: raise TypeError( - "{klass} cannot perform the operation {op}".format( - klass=type(self).__name__, op=name - ) + f"{type(self).__name__} cannot perform the operation {name}" ) return func(skipna=skipna, **kwds)