@@ -115,9 +115,9 @@ def __init__(self, values, placement, ndim=None, fastpath=False):
115
115
self .values = values
116
116
117
117
if ndim and len (self .mgr_locs ) != len (self .values ):
118
- raise ValueError ('Wrong number of items passed %d, placement '
119
- ' implies %d' % ( len ( self . values ),
120
- len (self .mgr_locs )))
118
+ raise ValueError (
119
+ 'Wrong number of items passed {val}, placement implies '
120
+ '{mgr}' . format ( val = len ( self . values ), mgr = len (self .mgr_locs )))
121
121
122
122
@property
123
123
def _consolidate_key (self ):
@@ -236,13 +236,15 @@ def __unicode__(self):
236
236
name = pprint_thing (self .__class__ .__name__ )
237
237
if self ._is_single_block :
238
238
239
- result = '%s: %s dtype: %s' % (name , len (self ), self .dtype )
239
+ result = '{name}: {len} dtype: {dtype}' .format (
240
+ name = name , len = len (self ), dtype = self .dtype )
240
241
241
242
else :
242
243
243
244
shape = ' x ' .join ([pprint_thing (s ) for s in self .shape ])
244
- result = '%s: %s, %s, dtype: %s' % (name , pprint_thing (
245
- self .mgr_locs .indexer ), shape , self .dtype )
245
+ result = '{name}: {index}, {shape}, dtype: {dtype}' .format (
246
+ name = name , index = pprint_thing (self .mgr_locs .indexer ),
247
+ shape = shape , dtype = self .dtype )
246
248
247
249
return result
248
250
@@ -310,7 +312,7 @@ def dtype(self):
310
312
311
313
@property
312
314
def ftype (self ):
313
- return "%s:%s" % ( self .dtype , self ._ftype )
315
+ return "{dtype}:{ftype}" . format ( dtype = self .dtype , ftype = self ._ftype )
314
316
315
317
def merge (self , other ):
316
318
return _merge_blocks ([self , other ])
@@ -330,7 +332,8 @@ def reindex_axis(self, indexer, method=None, axis=1, fill_value=None,
330
332
Reindex using pre-computed indexer information
331
333
"""
332
334
if axis < 1 :
333
- raise AssertionError ('axis must be at least 1, got %d' % axis )
335
+ raise AssertionError (
336
+ 'axis must be at least 1, got {axis}' .format (axis = axis ))
334
337
if fill_value is None :
335
338
fill_value = self .fill_value
336
339
@@ -634,11 +637,13 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
634
637
635
638
if newb .is_numeric and self .is_numeric :
636
639
if newb .shape != self .shape :
637
- raise TypeError ("cannot set astype for copy = [%s] for dtype "
638
- "(%s [%s]) with smaller itemsize that current "
639
- "(%s [%s])" % (copy , self .dtype .name ,
640
- self .itemsize , newb .dtype .name ,
641
- newb .itemsize ))
640
+ raise TypeError (
641
+ "cannot set astype for copy = [{copy}] for dtype "
642
+ "({dtype} [{itemsize}]) with smaller itemsize than "
643
+ "current ({newb_dtype} [{newb_size}])" .format (
644
+ copy = copy , dtype = self .dtype .name ,
645
+ itemsize = self .itemsize , newb_dtype = newb .dtype .name ,
646
+ newb_size = newb .itemsize ))
642
647
return newb
643
648
644
649
def convert (self , copy = True , ** kwargs ):
@@ -1306,9 +1311,10 @@ def eval(self, func, other, errors='raise', try_cast=False, mgr=None):
1306
1311
is_transposed = True
1307
1312
else :
1308
1313
# this is a broadcast error heree
1309
- raise ValueError ("cannot broadcast shape [%s] with block "
1310
- "values [%s]" % (values .T .shape ,
1311
- other .shape ))
1314
+ raise ValueError (
1315
+ "cannot broadcast shape [{t_shape}] with "
1316
+ "block values [{oth_shape}]" .format (
1317
+ t_shape = values .T .shape , oth_shape = other .shape ))
1312
1318
1313
1319
transf = (lambda x : x .T ) if is_transposed else (lambda x : x )
1314
1320
@@ -1363,8 +1369,9 @@ def handle_error():
1363
1369
1364
1370
if errors == 'raise' :
1365
1371
# The 'detail' variable is defined in outer scope.
1366
- raise TypeError ('Could not operate %s with block values %s' %
1367
- (repr (other ), str (detail ))) # noqa
1372
+ raise TypeError (
1373
+ 'Could not operate {other!r} with block values '
1374
+ '{detail!s}' .format (other = other , detail = detail )) # noqa
1368
1375
else :
1369
1376
# return the values
1370
1377
result = np .empty (values .shape , dtype = 'O' )
@@ -1391,11 +1398,12 @@ def handle_error():
1391
1398
# differentiate between an invalid ndarray-ndarray comparison
1392
1399
# and an invalid type comparison
1393
1400
if isinstance (values , np .ndarray ) and is_list_like (other ):
1394
- raise ValueError ('Invalid broadcasting comparison [%s] '
1395
- 'with block values' % repr (other ))
1401
+ raise ValueError (
1402
+ 'Invalid broadcasting comparison [{other!r}] with '
1403
+ 'block values' .format (other = other ))
1396
1404
1397
- raise TypeError ('Could not compare [%s] with block values' %
1398
- repr ( other ))
1405
+ raise TypeError ('Could not compare [{other!r}] '
1406
+ 'with block values' . format ( other = other ))
1399
1407
1400
1408
# transpose if needed
1401
1409
result = transf (result )
@@ -1466,8 +1474,9 @@ def func(cond, values, other):
1466
1474
cond , values , other ))
1467
1475
except Exception as detail :
1468
1476
if errors == 'raise' :
1469
- raise TypeError ('Could not operate [%s] with block values '
1470
- '[%s]' % (repr (other ), str (detail )))
1477
+ raise TypeError (
1478
+ 'Could not operate [{other!r}] with block values '
1479
+ '[{detail!s}]' .format (other = other , detail = detail ))
1471
1480
else :
1472
1481
# return the values
1473
1482
result = np .empty (values .shape , dtype = 'float64' )
@@ -2894,7 +2903,8 @@ def reindex_axis(self, indexer, method=None, axis=1, fill_value=None,
2894
2903
Reindex using pre-computed indexer information
2895
2904
"""
2896
2905
if axis < 1 :
2897
- raise AssertionError ('axis must be at least 1, got %d' % axis )
2906
+ raise AssertionError (
2907
+ 'axis must be at least 1, got {axis}' .format (axis = axis ))
2898
2908
2899
2909
# taking on the 0th axis always here
2900
2910
if fill_value is None :
@@ -3020,9 +3030,10 @@ def __init__(self, blocks, axes, do_integrity_check=True, fastpath=True):
3020
3030
"items" )
3021
3031
else :
3022
3032
if self .ndim != block .ndim :
3023
- raise AssertionError ('Number of Block dimensions (%d) '
3024
- 'must equal number of axes (%d)' %
3025
- (block .ndim , self .ndim ))
3033
+ raise AssertionError (
3034
+ 'Number of Block dimensions ({block}) must equal '
3035
+ 'number of axes ({self})' .format (block = block .ndim ,
3036
+ self = self .ndim ))
3026
3037
3027
3038
if do_integrity_check :
3028
3039
self ._verify_integrity ()
@@ -3064,9 +3075,9 @@ def set_axis(self, axis, new_labels):
3064
3075
new_len = len (new_labels )
3065
3076
3066
3077
if new_len != old_len :
3067
- raise ValueError ('Length mismatch: Expected axis has %d elements, '
3068
- ' new values have %d elements' %
3069
- ( old_len , new_len ))
3078
+ raise ValueError (
3079
+ 'Length mismatch: Expected axis has {old} elements, new '
3080
+ 'values have {new} elements' . format ( old = old_len , new = new_len ))
3070
3081
3071
3082
self .axes [axis ] = new_labels
3072
3083
@@ -3223,12 +3234,12 @@ def __unicode__(self):
3223
3234
output = pprint_thing (self .__class__ .__name__ )
3224
3235
for i , ax in enumerate (self .axes ):
3225
3236
if i == 0 :
3226
- output += u ('\n Items: %s' ) % ax
3237
+ output += u ('\n Items: {ax}' . format ( ax = ax ))
3227
3238
else :
3228
- output += u ('\n Axis %d: %s' ) % ( i , ax )
3239
+ output += u ('\n Axis {i}: {ax}' . format ( i = i , ax = ax ) )
3229
3240
3230
3241
for block in self .blocks :
3231
- output += u ('\n %s' ) % pprint_thing (block )
3242
+ output += u ('\n {block}' . format ( block = pprint_thing (block )) )
3232
3243
return output
3233
3244
3234
3245
def _verify_integrity (self ):
@@ -3732,8 +3743,8 @@ def to_dict(self, copy=True):
3732
3743
3733
3744
def xs (self , key , axis = 1 , copy = True , takeable = False ):
3734
3745
if axis < 1 :
3735
- raise AssertionError ('Can only take xs across axis >= 1, got %d' %
3736
- axis )
3746
+ raise AssertionError (
3747
+ 'Can only take xs across axis >= 1, got {ax}' . format ( ax = axis ) )
3737
3748
3738
3749
# take by position
3739
3750
if takeable :
@@ -4284,8 +4295,9 @@ def _is_indexed_like(self, other):
4284
4295
Check all axes except items
4285
4296
"""
4286
4297
if self .ndim != other .ndim :
4287
- raise AssertionError ('Number of dimensions must agree '
4288
- 'got %d and %d' % (self .ndim , other .ndim ))
4298
+ raise AssertionError (
4299
+ 'Number of dimensions must agree got {ndim} and '
4300
+ '{oth_ndim}' .format (ndim = self .ndim , oth_ndim = other .ndim ))
4289
4301
for ax , oax in zip (self .axes [1 :], other .axes [1 :]):
4290
4302
if not ax .equals (oax ):
4291
4303
return False
@@ -4934,12 +4946,14 @@ def _maybe_compare(a, b, op):
4934
4946
type_names = [type (a ).__name__ , type (b ).__name__ ]
4935
4947
4936
4948
if is_a_array :
4937
- type_names [0 ] = 'ndarray(dtype=%s)' % a .dtype
4949
+ type_names [0 ] = 'ndarray(dtype={dtype})' . format ( dtype = a .dtype )
4938
4950
4939
4951
if is_b_array :
4940
- type_names [1 ] = 'ndarray(dtype=%s)' % b .dtype
4952
+ type_names [1 ] = 'ndarray(dtype={dtype})' . format ( dtype = b .dtype )
4941
4953
4942
- raise TypeError ("Cannot compare types %r and %r" % tuple (type_names ))
4954
+ raise TypeError (
4955
+ "Cannot compare types {a!r} and {b!r}" .format (a = type_names [0 ],
4956
+ b = type_names [1 ]))
4943
4957
return result
4944
4958
4945
4959
@@ -5017,17 +5031,17 @@ def items_overlap_with_suffix(left, lsuffix, right, rsuffix):
5017
5031
return left , right
5018
5032
else :
5019
5033
if not lsuffix and not rsuffix :
5020
- raise ValueError ('columns overlap but no suffix specified: %s' %
5021
- to_rename )
5034
+ raise ValueError ('columns overlap but no suffix specified: '
5035
+ '{rename}' . format ( rename = to_rename ) )
5022
5036
5023
5037
def lrenamer (x ):
5024
5038
if x in to_rename :
5025
- return '%s%s' % ( x , lsuffix )
5039
+ return '{x}{lsuffix}' . format ( x = x , lsuffix = lsuffix )
5026
5040
return x
5027
5041
5028
5042
def rrenamer (x ):
5029
5043
if x in to_rename :
5030
- return '%s%s' % ( x , rsuffix )
5044
+ return '{x}{rsuffix}' . format ( x = x , rsuffix = rsuffix )
5031
5045
return x
5032
5046
5033
5047
return (_transform_index (left , lrenamer ),
@@ -5519,8 +5533,9 @@ def __init__(self, block, shape, indexers=None):
5519
5533
self .shape = shape
5520
5534
5521
5535
def __repr__ (self ):
5522
- return '%s(%r, %s)' % (self .__class__ .__name__ , self .block ,
5523
- self .indexers )
5536
+ return '{name}({block!r}, {indexers})' .format (
5537
+ name = self .__class__ .__name__ , block = self .block ,
5538
+ indexers = self .indexers )
5524
5539
5525
5540
@cache_readonly
5526
5541
def needs_filling (self ):
0 commit comments