@@ -1464,9 +1464,9 @@ def extract(r):
1464
1464
for n in range (len (columns [0 ])):
1465
1465
if all (compat .to_str (c [n ]) in self .unnamed_cols for c in columns ):
1466
1466
raise ParserError (
1467
- "Passed header=[%s ] are too many rows for this "
1467
+ "Passed header=[{header} ] are too many rows for this "
1468
1468
"multi_index of columns"
1469
- % ',' .join (str (x ) for x in self .header )
1469
+ . format ( header = ',' .join (str (x ) for x in self .header ) )
1470
1470
)
1471
1471
1472
1472
# Clean the column names (if we have an index_col).
@@ -1499,9 +1499,11 @@ def _maybe_dedup_names(self, names):
1499
1499
counts [col ] = cur_count + 1
1500
1500
1501
1501
if is_potential_mi :
1502
- col = col [:- 1 ] + ('%s.%d' % (col [- 1 ], cur_count ),)
1502
+ col = col [:- 1 ] + ('{column}.{count}' .format (
1503
+ column = col [- 1 ], count = cur_count ),)
1503
1504
else :
1504
- col = '%s.%d' % (col , cur_count )
1505
+ col = '{column}.{count}' .format (
1506
+ column = col , count = cur_count )
1505
1507
cur_count = counts [col ]
1506
1508
1507
1509
names [i ] = col
@@ -1548,7 +1550,7 @@ def _get_simple_index(self, data, columns):
1548
1550
def ix (col ):
1549
1551
if not isinstance (col , compat .string_types ):
1550
1552
return col
1551
- raise ValueError ('Index %s invalid' % col )
1553
+ raise ValueError ('Index {col} invalid' . format ( col = col ) )
1552
1554
1553
1555
to_remove = []
1554
1556
index = []
@@ -1572,8 +1574,8 @@ def _get_name(icol):
1572
1574
return icol
1573
1575
1574
1576
if col_names is None :
1575
- raise ValueError (('Must supply column order to use %s as '
1576
- 'index' ) % str ( icol ))
1577
+ raise ValueError (('Must supply column order to use {icol!s} '
1578
+ 'as index' ). format ( icol = icol ))
1577
1579
1578
1580
for i , c in enumerate (col_names ):
1579
1581
if i == icol :
@@ -1688,7 +1690,8 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
1688
1690
1689
1691
result [c ] = cvals
1690
1692
if verbose and na_count :
1691
- print ('Filled %d NA values in column %s' % (na_count , str (c )))
1693
+ print ('Filled {count} NA values in column {c!s}' .format (
1694
+ count = na_count , c = c ))
1692
1695
return result
1693
1696
1694
1697
def _infer_types (self , values , na_values , try_num_bool = True ):
@@ -1789,8 +1792,10 @@ def _cast_types(self, values, cast_type, column):
1789
1792
values = astype_nansafe (values , cast_type ,
1790
1793
copy = True , skipna = True )
1791
1794
except ValueError :
1792
- raise ValueError ("Unable to convert column %s to "
1793
- "type %s" % (column , cast_type ))
1795
+ raise ValueError (
1796
+ "Unable to convert column {column} to type "
1797
+ "{cast_type}" .format (
1798
+ column = column , cast_type = cast_type ))
1794
1799
return values
1795
1800
1796
1801
def _do_date_conversions (self , names , data ):
@@ -1853,7 +1858,7 @@ def __init__(self, src, **kwds):
1853
1858
1854
1859
if self .names is None :
1855
1860
if self .prefix :
1856
- self .names = ['%s%d' % ( self .prefix , i )
1861
+ self .names = ['{prefix}{i}' . format ( prefix = self .prefix , i = i )
1857
1862
for i in range (self ._reader .table_width )]
1858
1863
else :
1859
1864
self .names = lrange (self ._reader .table_width )
@@ -2255,10 +2260,11 @@ def __init__(self, f, **kwds):
2255
2260
raise ValueError ('Only length-1 decimal markers supported' )
2256
2261
2257
2262
if self .thousands is None :
2258
- self .nonnum = re .compile ('[^-^0-9^%s]+' % self .decimal )
2263
+ self .nonnum = re .compile (
2264
+ r'[^-^0-9^{decimal}]+' .format (decimal = self .decimal ))
2259
2265
else :
2260
- self .nonnum = re .compile ('[^-^0-9^%s^%s ]+' % ( self . thousands ,
2261
- self .decimal ))
2266
+ self .nonnum = re .compile (r '[^-^0-9^{thousands}^{decimal} ]+'. format (
2267
+ thousands = self . thousands , decimal = self .decimal ))
2262
2268
2263
2269
def _set_no_thousands_columns (self ):
2264
2270
# Create a set of column ids that are not to be stripped of thousands
@@ -2497,8 +2503,8 @@ def _infer_columns(self):
2497
2503
except StopIteration :
2498
2504
if self .line_pos < hr :
2499
2505
raise ValueError (
2500
- 'Passed header=%s but only %d lines in file '
2501
- % (hr , self .line_pos + 1 ))
2506
+ 'Passed header={hr} but only {pos} lines in '
2507
+ 'file' . format (hr = hr , pos = ( self .line_pos + 1 ) ))
2502
2508
2503
2509
# We have an empty file, so check
2504
2510
# if columns are provided. That will
@@ -2539,7 +2545,8 @@ def _infer_columns(self):
2539
2545
2540
2546
while cur_count > 0 :
2541
2547
counts [col ] = cur_count + 1
2542
- col = "%s.%d" % (col , cur_count )
2548
+ col = u'{column}.{count}' .format (
2549
+ column = col , count = cur_count )
2543
2550
cur_count = counts [col ]
2544
2551
2545
2552
this_columns [i ] = col
@@ -2607,8 +2614,8 @@ def _infer_columns(self):
2607
2614
2608
2615
if not names :
2609
2616
if self .prefix :
2610
- columns = [['%s%d' % ( self . prefix , i )
2611
- for i in range (ncols )]]
2617
+ columns = [['{prefix}{idx}' . format (
2618
+ prefix = self . prefix , idx = i ) for i in range (ncols )]]
2612
2619
else :
2613
2620
columns = [lrange (ncols )]
2614
2621
columns = self ._handle_usecols (columns , columns [0 ])
@@ -3035,8 +3042,9 @@ def _rows_to_cols(self, content):
3035
3042
content .append (l )
3036
3043
3037
3044
for row_num , actual_len in bad_lines :
3038
- msg = ('Expected %d fields in line %d, saw %d' %
3039
- (col_len , row_num + 1 , actual_len ))
3045
+ msg = ('Expected {col_len} fields in line {line}, saw '
3046
+ '{length}' .format (col_len = col_len , line = (row_num + 1 ),
3047
+ length = actual_len ))
3040
3048
if (self .delimiter and
3041
3049
len (self .delimiter ) > 1 and
3042
3050
self .quoting != csv .QUOTE_NONE ):
@@ -3207,8 +3215,9 @@ def _isindex(colspec):
3207
3215
new_name , col , old_names = _try_convert_dates (
3208
3216
converter , colspec , data_dict , orig_names )
3209
3217
if new_name in data_dict :
3210
- raise ValueError ('New date column already in dict %s' %
3211
- new_name )
3218
+ raise ValueError (
3219
+ 'New date column already in dict {name}' .format (
3220
+ name = new_name ))
3212
3221
new_data [new_name ] = col
3213
3222
new_cols .append (new_name )
3214
3223
date_cols .update (old_names )
@@ -3217,8 +3226,8 @@ def _isindex(colspec):
3217
3226
# dict of new name to column list
3218
3227
for new_name , colspec in compat .iteritems (parse_spec ):
3219
3228
if new_name in data_dict :
3220
- raise ValueError ('Date column %s already in dict' %
3221
- new_name )
3229
+ raise ValueError (
3230
+ 'Date column {name} already in dict' . format ( name = new_name ) )
3222
3231
3223
3232
_ , col , old_names = _try_convert_dates (converter , colspec ,
3224
3233
data_dict , orig_names )
@@ -3397,7 +3406,7 @@ def _stringify_na_values(na_values):
3397
3406
# we are like 999 here
3398
3407
if v == int (v ):
3399
3408
v = int (v )
3400
- result .append ("%s .0" % v )
3409
+ result .append ("{value} .0" . format ( value = v ) )
3401
3410
result .append (str (v ))
3402
3411
3403
3412
result .append (v )
@@ -3542,8 +3551,8 @@ def get_rows(self, infer_nrows, skiprows=None):
3542
3551
3543
3552
def detect_colspecs (self , infer_nrows = 100 , skiprows = None ):
3544
3553
# Regex escape the delimiters
3545
- delimiters = '' .join (r'\%s' % x for x in self .delimiter )
3546
- pattern = re .compile ('([^%s ]+)' % delimiters )
3554
+ delimiters = '' .join (r'\{}' . format ( x ) for x in self .delimiter )
3555
+ pattern = re .compile ('([^{} ]+)' . format ( delimiters ) )
3547
3556
rows = self .get_rows (infer_nrows , skiprows )
3548
3557
if not rows :
3549
3558
raise EmptyDataError ("No rows from which to infer column width" )
0 commit comments