@@ -63,9 +63,9 @@ def _create_methods(arith_method, comp_method, bool_method,
63
63
64
64
def names (x ):
65
65
if x [- 1 ] == "_" :
66
- return "__%s_" % x
66
+ return "__{name}_" . format ( name = x )
67
67
else :
68
- return "__%s__" % x
68
+ return "__{name}__" . format ( name = x )
69
69
else :
70
70
names = lambda x : x
71
71
@@ -388,8 +388,8 @@ def _validate(self, lvalues, rvalues, name):
388
388
if name not in ('__div__' , '__truediv__' , '__mul__' , '__rmul__' ):
389
389
raise TypeError ("can only operate on a timedelta and an "
390
390
"integer or a float for division and "
391
- "multiplication, but the operator [%s] was "
392
- "passed" % name )
391
+ "multiplication, but the operator [{name}] "
392
+ "was passed" . format ( name = name ) )
393
393
394
394
# 2 timedeltas
395
395
elif ((self .is_timedelta_lhs and
@@ -400,9 +400,9 @@ def _validate(self, lvalues, rvalues, name):
400
400
if name not in ('__div__' , '__rdiv__' , '__truediv__' ,
401
401
'__rtruediv__' , '__add__' , '__radd__' , '__sub__' ,
402
402
'__rsub__' ):
403
- raise TypeError ("can only operate on a timedeltas for "
404
- "addition , subtraction, and division, but the"
405
- " operator [%s ] was passed" % name )
403
+ raise TypeError ("can only operate on a timedeltas for addition "
404
+ ", subtraction, and division, but the operator "
405
+ " [{name} ] was passed" . format ( name = name ) )
406
406
407
407
# datetime and timedelta/DateOffset
408
408
elif (self .is_datetime_lhs and
@@ -411,23 +411,24 @@ def _validate(self, lvalues, rvalues, name):
411
411
if name not in ('__add__' , '__radd__' , '__sub__' ):
412
412
raise TypeError ("can only operate on a datetime with a rhs of "
413
413
"a timedelta/DateOffset for addition and "
414
- "subtraction, but the operator [%s ] was "
415
- "passed" % name )
414
+ "subtraction, but the operator [{name} ] was "
415
+ "passed" . format ( name = name ) )
416
416
417
417
elif (self .is_datetime_rhs and
418
418
(self .is_timedelta_lhs or self .is_offset_lhs )):
419
419
if name not in ('__add__' , '__radd__' , '__rsub__' ):
420
420
raise TypeError ("can only operate on a timedelta/DateOffset "
421
421
"with a rhs of a datetime for addition, "
422
- "but the operator [%s] was passed" % name )
422
+ "but the operator [{name}] was passed"
423
+ .format (name = name ))
423
424
424
425
# 2 datetimes
425
426
elif self .is_datetime_lhs and self .is_datetime_rhs :
426
427
427
428
if name not in ('__sub__' , '__rsub__' ):
428
429
raise TypeError ("can only operate on a datetimes for"
429
- " subtraction, but the operator [%s ] was"
430
- " passed" % name )
430
+ " subtraction, but the operator [{name} ] was"
431
+ " passed" . format ( name = name ) )
431
432
432
433
# if tz's must be equal (same or None)
433
434
if getattr (lvalues , 'tz' , None ) != getattr (rvalues , 'tz' , None ):
@@ -439,8 +440,8 @@ def _validate(self, lvalues, rvalues, name):
439
440
440
441
if name not in ('__add__' , '__radd__' ):
441
442
raise TypeError ("can only operate on a timedelta/DateOffset "
442
- "and a datetime for addition, but the "
443
- "operator [%s ] was passed" % name )
443
+ "and a datetime for addition, but the operator "
444
+ " [{name} ] was passed" . format ( name = name ) )
444
445
else :
445
446
raise TypeError ('cannot operate on a series without a rhs '
446
447
'of a series/ndarray of type datetime64[ns] '
@@ -498,7 +499,7 @@ def _convert_to_array(self, values, name=None, other=None):
498
499
values = values .to_timestamp ().to_series ()
499
500
elif name not in ('__truediv__' , '__div__' , '__mul__' , '__rmul__' ):
500
501
raise TypeError ("incompatible type for a datetime/timedelta "
501
- "operation [{0 }]" .format (name ))
502
+ "operation [{name }]" .format (name = name ))
502
503
elif inferred_type == 'floating' :
503
504
if (isna (values ).all () and
504
505
name in ('__add__' , '__radd__' , '__sub__' , '__rsub__' )):
@@ -508,8 +509,9 @@ def _convert_to_array(self, values, name=None, other=None):
508
509
elif self ._is_offset (values ):
509
510
return values
510
511
else :
511
- raise TypeError ("incompatible type [{0}] for a datetime/timedelta"
512
- " operation" .format (np .array (values ).dtype ))
512
+ raise TypeError ("incompatible type [{dtype}] for a "
513
+ "datetime/timedelta operation"
514
+ .format (dtype = np .array (values ).dtype ))
513
515
514
516
return values
515
517
@@ -866,8 +868,8 @@ def wrapper(self, other, axis=None):
866
868
with np .errstate (all = 'ignore' ):
867
869
res = na_op (values , other )
868
870
if is_scalar (res ):
869
- raise TypeError ('Could not compare %s type with Series' %
870
- type (other ))
871
+ raise TypeError ('Could not compare {typ} type with Series'
872
+ . format ( typ = type (other ) ))
871
873
872
874
# always return a full value series here
873
875
res = _values_from_object (res )
@@ -906,9 +908,10 @@ def na_op(x, y):
906
908
y = bool (y )
907
909
result = lib .scalar_binop (x , y , op )
908
910
except :
909
- raise TypeError ("cannot compare a dtyped [{0}] array with "
910
- "a scalar of type [{1}]" .format (
911
- x .dtype , type (y ).__name__ ))
911
+ msg = ("cannot compare a dtyped [{dtype}] array "
912
+ "with a scalar of type [{type}]"
913
+ ).format (dtype = x .dtype , type = type (y ).__name__ )
914
+ raise TypeError (msg )
912
915
913
916
return result
914
917
@@ -1140,14 +1143,17 @@ def _align_method_FRAME(left, right, axis):
1140
1143
""" convert rhs to meet lhs dims if input is list, tuple or np.ndarray """
1141
1144
1142
1145
def to_series (right ):
1143
- msg = 'Unable to coerce to Series, length must be {0}: given {1}'
1146
+ msg = ('Unable to coerce to Series, length must be {req_len}: '
1147
+ 'given {given_len}' )
1144
1148
if axis is not None and left ._get_axis_name (axis ) == 'index' :
1145
1149
if len (left .index ) != len (right ):
1146
- raise ValueError (msg .format (len (left .index ), len (right )))
1150
+ raise ValueError (msg .format (req_len = len (left .index ),
1151
+ given_len = len (right )))
1147
1152
right = left ._constructor_sliced (right , index = left .index )
1148
1153
else :
1149
1154
if len (left .columns ) != len (right ):
1150
- raise ValueError (msg .format (len (left .columns ), len (right )))
1155
+ raise ValueError (msg .format (req_len = len (left .columns ),
1156
+ given_len = len (right )))
1151
1157
right = left ._constructor_sliced (right , index = left .columns )
1152
1158
return right
1153
1159
@@ -1161,15 +1167,16 @@ def to_series(right):
1161
1167
1162
1168
elif right .ndim == 2 :
1163
1169
if left .shape != right .shape :
1164
- msg = ("Unable to coerce to DataFrame, "
1165
- "shape must be {0}: given {1}" )
1166
- raise ValueError (msg .format (left .shape , right .shape ))
1170
+ msg = ("Unable to coerce to DataFrame, shape "
1171
+ "must be {req_shape}: given {given_shape}"
1172
+ ).format (req_shape = left .shape , given_shape = right .shape )
1173
+ raise ValueError (msg )
1167
1174
1168
1175
right = left ._constructor (right , index = left .index ,
1169
1176
columns = left .columns )
1170
1177
else :
1171
- msg = 'Unable to coerce to Series/DataFrame, dim must be <= 2: {0} '
1172
- raise ValueError ( msg .format (right .shape , ))
1178
+ raise ValueError ( 'Unable to coerce to Series/DataFrame, dim '
1179
+ 'must be <= 2: {dim}' .format (dim = right .shape ))
1173
1180
1174
1181
return right
1175
1182
@@ -1278,7 +1285,8 @@ def na_op(x, y):
1278
1285
1279
1286
return result
1280
1287
1281
- @Appender ('Wrapper for flexible comparison methods %s' % name )
1288
+ @Appender ('Wrapper for flexible comparison methods {name}'
1289
+ .format (name = name ))
1282
1290
def f (self , other , axis = default_axis , level = None ):
1283
1291
1284
1292
other = _align_method_FRAME (self , other , axis )
@@ -1299,7 +1307,7 @@ def f(self, other, axis=default_axis, level=None):
1299
1307
1300
1308
1301
1309
def _comp_method_FRAME (func , name , str_rep , masker = False ):
1302
- @Appender ('Wrapper for comparison method %s' % name )
1310
+ @Appender ('Wrapper for comparison method {name}' . format ( name = name ) )
1303
1311
def f (self , other ):
1304
1312
if isinstance (other , pd .DataFrame ): # Another DataFrame
1305
1313
return self ._compare_frame (other , func , str_rep )
@@ -1349,9 +1357,9 @@ def na_op(x, y):
1349
1357
# work only for scalars
1350
1358
def f (self , other ):
1351
1359
if not is_scalar (other ):
1352
- raise ValueError ('Simple arithmetic with %s can only be '
1353
- 'done with scalar values' %
1354
- self ._constructor .__name__ )
1360
+ raise ValueError ('Simple arithmetic with {name} can only be '
1361
+ 'done with scalar values'
1362
+ . format ( name = self ._constructor .__name__ ) )
1355
1363
1356
1364
return self ._combine (other , op )
1357
1365
@@ -1384,7 +1392,7 @@ def na_op(x, y):
1384
1392
1385
1393
return result
1386
1394
1387
- @Appender ('Wrapper for comparison method %s' % name )
1395
+ @Appender ('Wrapper for comparison method {name}' . format ( name = name ) )
1388
1396
def f (self , other , axis = None ):
1389
1397
# Validate the axis parameter
1390
1398
if axis is not None :
@@ -1394,8 +1402,8 @@ def f(self, other, axis=None):
1394
1402
return self ._compare_constructor (other , na_op , try_cast = False )
1395
1403
elif isinstance (other , (self ._constructor_sliced , pd .DataFrame ,
1396
1404
ABCSeries )):
1397
- raise Exception ("input needs alignment for this object [%s]" %
1398
- self ._constructor )
1405
+ raise Exception ("input needs alignment for this object [{object}]"
1406
+ . format ( object = self ._constructor ) )
1399
1407
else :
1400
1408
return self ._combine_const (other , na_op , try_cast = False )
1401
1409
0 commit comments