@@ -114,9 +114,7 @@ def __setattr__(self, key, value):
114
114
or key in type (self ).__dict__
115
115
or getattr (self , key , None ) is not None
116
116
):
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 } '" )
120
118
object .__setattr__ (self , key , value )
121
119
122
120
@@ -220,28 +218,22 @@ def _obj_with_exclusions(self):
220
218
221
219
def __getitem__ (self , key ):
222
220
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" )
228
222
229
223
if isinstance (key , (list , tuple , ABCSeries , ABCIndexClass , np .ndarray )):
230
224
if len (self .obj .columns .intersection (key )) != len (key ):
231
225
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 ]} " )
235
227
return self ._gotitem (list (key ), ndim = 2 )
236
228
237
229
elif not getattr (self , "as_index" , False ):
238
230
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 } " )
240
232
return self ._gotitem (key , ndim = 2 )
241
233
242
234
else :
243
235
if key not in self .obj :
244
- raise KeyError ("Column not found: {key}" . format ( key = key ) )
236
+ raise KeyError (f "Column not found: { key } " )
245
237
return self ._gotitem (key , ndim = 1 )
246
238
247
239
def _gotitem (self , key , ndim , subset = None ):
@@ -293,8 +285,7 @@ def _try_aggregate_string_function(self, arg: str, *args, **kwargs):
293
285
return f (self , * args , ** kwargs )
294
286
295
287
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"
298
289
)
299
290
300
291
def _aggregate (self , arg , * args , ** kwargs ):
@@ -359,7 +350,7 @@ def _aggregate(self, arg, *args, **kwargs):
359
350
elif isinstance (obj , ABCSeries ):
360
351
raise SpecificationError ("nested renamer is not supported" )
361
352
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!" )
363
354
364
355
arg = new_arg
365
356
@@ -1101,9 +1092,7 @@ def _reduce(
1101
1092
func = getattr (self , name , None )
1102
1093
if func is None :
1103
1094
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 } "
1107
1096
)
1108
1097
return func (skipna = skipna , ** kwds )
1109
1098
0 commit comments