Skip to content

Commit 21e2cd7

Browse files
dplutchoproost
authored andcommitted
f-string update for core.base. (pandas-dev#30023)
1 parent 9d3da3f commit 21e2cd7

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

pandas/core/base.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ def __setattr__(self, key, value):
114114
or key in type(self).__dict__
115115
or getattr(self, key, None) is not None
116116
):
117-
raise AttributeError(
118-
"You cannot add any new attribute '{key}'".format(key=key)
119-
)
117+
raise AttributeError(f"You cannot add any new attribute '{key}'")
120118
object.__setattr__(self, key, value)
121119

122120

@@ -220,28 +218,22 @@ def _obj_with_exclusions(self):
220218

221219
def __getitem__(self, key):
222220
if self._selection is not None:
223-
raise IndexError(
224-
"Column(s) {selection} already selected".format(
225-
selection=self._selection
226-
)
227-
)
221+
raise IndexError(f"Column(s) {self._selection} already selected")
228222

229223
if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray)):
230224
if len(self.obj.columns.intersection(key)) != len(key):
231225
bad_keys = list(set(key).difference(self.obj.columns))
232-
raise KeyError(
233-
"Columns not found: {missing}".format(missing=str(bad_keys)[1:-1])
234-
)
226+
raise KeyError(f"Columns not found: {str(bad_keys)[1:-1]}")
235227
return self._gotitem(list(key), ndim=2)
236228

237229
elif not getattr(self, "as_index", False):
238230
if key not in self.obj.columns:
239-
raise KeyError("Column not found: {key}".format(key=key))
231+
raise KeyError(f"Column not found: {key}")
240232
return self._gotitem(key, ndim=2)
241233

242234
else:
243235
if key not in self.obj:
244-
raise KeyError("Column not found: {key}".format(key=key))
236+
raise KeyError(f"Column not found: {key}")
245237
return self._gotitem(key, ndim=1)
246238

247239
def _gotitem(self, key, ndim, subset=None):
@@ -293,8 +285,7 @@ def _try_aggregate_string_function(self, arg: str, *args, **kwargs):
293285
return f(self, *args, **kwargs)
294286

295287
raise AttributeError(
296-
"'{arg}' is not a valid function for "
297-
"'{cls}' object".format(arg=arg, cls=type(self).__name__)
288+
f"'{arg}' is not a valid function for '{type(self).__name__}' object"
298289
)
299290

300291
def _aggregate(self, arg, *args, **kwargs):
@@ -359,7 +350,7 @@ def _aggregate(self, arg, *args, **kwargs):
359350
elif isinstance(obj, ABCSeries):
360351
raise SpecificationError("nested renamer is not supported")
361352
elif isinstance(obj, ABCDataFrame) and k not in obj.columns:
362-
raise KeyError("Column '{col}' does not exist!".format(col=k))
353+
raise KeyError(f"Column '{k}' does not exist!")
363354

364355
arg = new_arg
365356

@@ -1101,9 +1092,7 @@ def _reduce(
11011092
func = getattr(self, name, None)
11021093
if func is None:
11031094
raise TypeError(
1104-
"{klass} cannot perform the operation {op}".format(
1105-
klass=type(self).__name__, op=name
1106-
)
1095+
f"{type(self).__name__} cannot perform the operation {name}"
11071096
)
11081097
return func(skipna=skipna, **kwds)
11091098

0 commit comments

Comments
 (0)