@@ -52,8 +52,8 @@ def _arith_method(op, name, str_rep=None, default_axis=None, fill_zeros=None,
52
52
def wrapper (self , other ):
53
53
if isinstance (other , np .ndarray ):
54
54
if len (self ) != len (other ):
55
- raise AssertionError ("length mismatch: %d vs. %d" %
56
- ( len (self ), len (other )))
55
+ raise AssertionError ("length mismatch: {self} vs. {other}"
56
+ . format ( self = len (self ), other = len (other )))
57
57
if not isinstance (other , ABCSparseArray ):
58
58
dtype = getattr (other , 'dtype' , None )
59
59
other = SparseArray (other , fill_value = self .fill_value ,
@@ -66,7 +66,8 @@ def wrapper(self, other):
66
66
67
67
return _wrap_result (name , result , self .sp_index , fill )
68
68
else : # pragma: no cover
69
- raise TypeError ('operation with %s not supported' % type (other ))
69
+ raise TypeError ('operation with {other} not supported'
70
+ .format (other = type (other )))
70
71
71
72
if name .startswith ("__" ):
72
73
name = name [2 :- 2 ]
@@ -218,9 +219,9 @@ def __new__(cls, data, sparse_index=None, index=None, kind='integer',
218
219
else :
219
220
values = _sanitize_values (data )
220
221
if len (values ) != sparse_index .npoints :
221
- raise AssertionError ("Non array-like type {0 } must have "
222
- " the same length as the"
223
- " index" .format (type (values )))
222
+ raise AssertionError ("Non array-like type {type } must "
223
+ "have the same length as the index "
224
+ .format (type = type (values )))
224
225
# Create array, do *not* copy data by default
225
226
if copy :
226
227
subarr = np .array (values , dtype = dtype , copy = True )
@@ -330,9 +331,10 @@ def __len__(self):
330
331
return 0
331
332
332
333
def __unicode__ (self ):
333
- return '%s\n Fill: %s\n %s' % (printing .pprint_thing (self ),
334
- printing .pprint_thing (self .fill_value ),
335
- printing .pprint_thing (self .sp_index ))
334
+ return '{self}\n Fill: {fill}\n {index}' .format (
335
+ self = printing .pprint_thing (self ),
336
+ fill = printing .pprint_thing (self .fill_value ),
337
+ index = printing .pprint_thing (self .sp_index ))
336
338
337
339
def disable (self , other ):
338
340
raise NotImplementedError ('inplace binary ops not supported' )
@@ -377,8 +379,8 @@ def fill_value(self, value):
377
379
if is_dtype_equal (self .dtype , new_dtype ):
378
380
self ._fill_value = fill_value
379
381
else :
380
- msg = 'unable to set fill_value {0 } to {1 } dtype'
381
- raise ValueError (msg .format (value , self .dtype ))
382
+ msg = 'unable to set fill_value {fill } to {dtype } dtype'
383
+ raise ValueError (msg .format (fill = value , dtype = self .dtype ))
382
384
383
385
def get_values (self , fill = None ):
384
386
""" return a dense representation """
@@ -466,7 +468,8 @@ def take(self, indices, axis=0, allow_fill=True,
466
468
nv .validate_take (tuple (), kwargs )
467
469
468
470
if axis :
469
- raise ValueError ("axis must be 0, input was {0}" .format (axis ))
471
+ raise ValueError ("axis must be 0, input was {axis}"
472
+ .format (axis = axis ))
470
473
471
474
if is_integer (indices ):
472
475
# return scalar
@@ -482,12 +485,12 @@ def take(self, indices, axis=0, allow_fill=True,
482
485
'all indices must be >= -1' )
483
486
raise ValueError (msg )
484
487
elif (n <= indices ).any ():
485
- msg = 'index is out of bounds for size {0}'
486
- raise IndexError (msg . format ( n ) )
488
+ msg = 'index is out of bounds for size {size}' . format ( size = n )
489
+ raise IndexError (msg )
487
490
else :
488
491
if ((indices < - n ) | (n <= indices )).any ():
489
- msg = 'index is out of bounds for size {0}'
490
- raise IndexError (msg . format ( n ) )
492
+ msg = 'index is out of bounds for size {size}' . format ( size = n )
493
+ raise IndexError (msg )
491
494
492
495
indices = indices .astype (np .int32 )
493
496
if not (allow_fill and fill_value is not None ):
@@ -543,8 +546,8 @@ def astype(self, dtype=None, copy=True):
543
546
else :
544
547
fill_value = dtype .type (self .fill_value )
545
548
except ValueError :
546
- msg = 'unable to coerce current fill_value {0 } to {1 } dtype'
547
- raise ValueError (msg .format (self .fill_value , dtype ))
549
+ msg = 'unable to coerce current fill_value {fill } to {dtype } dtype'
550
+ raise ValueError (msg .format (fill = self .fill_value , dtype = dtype ))
548
551
return self ._simple_new (sp_values , self .sp_index ,
549
552
fill_value = fill_value )
550
553
0 commit comments