@@ -1463,9 +1463,9 @@ def extract(r):
1463
1463
for n in range (len (columns [0 ])):
1464
1464
if all (compat .to_str (c [n ]) in self .unnamed_cols for c in columns ):
1465
1465
raise ParserError (
1466
- "Passed header=[%s ] are too many rows for this "
1466
+ "Passed header=[{header} ] are too many rows for this "
1467
1467
"multi_index of columns"
1468
- % ',' .join (str (x ) for x in self .header )
1468
+ . format ( header = ',' .join (str (x ) for x in self .header ) )
1469
1469
)
1470
1470
1471
1471
# Clean the column names (if we have an index_col).
@@ -1498,9 +1498,10 @@ def _maybe_dedup_names(self, names):
1498
1498
counts [col ] = cur_count + 1
1499
1499
1500
1500
if is_potential_mi :
1501
- col = col [:- 1 ] + ('%s.%d' % (col [- 1 ], cur_count ),)
1501
+ col = col [:- 1 ] + ('{col}.{cnt}' .format (
1502
+ col = col [- 1 ], cnt = cur_count ),)
1502
1503
else :
1503
- col = '%s.%d' % (col , cur_count )
1504
+ col = '{col}.{cnt}' . format (col = col , cnt = cur_count )
1504
1505
cur_count = counts [col ]
1505
1506
1506
1507
names [i ] = col
@@ -1547,7 +1548,7 @@ def _get_simple_index(self, data, columns):
1547
1548
def ix (col ):
1548
1549
if not isinstance (col , compat .string_types ):
1549
1550
return col
1550
- raise ValueError ('Index %s invalid' % col )
1551
+ raise ValueError ('Index {col} invalid' . format ( col = col ) )
1551
1552
1552
1553
to_remove = []
1553
1554
index = []
@@ -1571,8 +1572,8 @@ def _get_name(icol):
1571
1572
return icol
1572
1573
1573
1574
if col_names is None :
1574
- raise ValueError (('Must supply column order to use %s as '
1575
- 'index' ) % str ( icol ))
1575
+ raise ValueError (('Must supply column order to use {icol!s} '
1576
+ 'as index' ). format ( icol = icol ))
1576
1577
1577
1578
for i , c in enumerate (col_names ):
1578
1579
if i == icol :
@@ -1683,7 +1684,8 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
1683
1684
1684
1685
result [c ] = cvals
1685
1686
if verbose and na_count :
1686
- print ('Filled %d NA values in column %s' % (na_count , str (c )))
1687
+ print ('Filled {count} NA values in column {c!s}' .format (
1688
+ count = na_count , c = c ))
1687
1689
return result
1688
1690
1689
1691
def _infer_types (self , values , na_values , try_num_bool = True ):
@@ -1770,8 +1772,9 @@ def _cast_types(self, values, cast_type, column):
1770
1772
values = astype_nansafe (values , cast_type ,
1771
1773
copy = True , skipna = True )
1772
1774
except ValueError :
1773
- raise ValueError ("Unable to convert column %s to "
1774
- "type %s" % (column , cast_type ))
1775
+ raise ValueError (
1776
+ "Unable to convert column {column} to type {type}" .format (
1777
+ column = column , type = cast_type ))
1775
1778
return values
1776
1779
1777
1780
def _do_date_conversions (self , names , data ):
@@ -1834,7 +1837,7 @@ def __init__(self, src, **kwds):
1834
1837
1835
1838
if self .names is None :
1836
1839
if self .prefix :
1837
- self .names = ['%s%d' % ( self .prefix , i )
1840
+ self .names = ['{prefix}{i}' . format ( prefix = self .prefix , i = i )
1838
1841
for i in range (self ._reader .table_width )]
1839
1842
else :
1840
1843
self .names = lrange (self ._reader .table_width )
@@ -2236,10 +2239,11 @@ def __init__(self, f, **kwds):
2236
2239
raise ValueError ('Only length-1 decimal markers supported' )
2237
2240
2238
2241
if self .thousands is None :
2239
- self .nonnum = re .compile ('[^-^0-9^%s]+' % self .decimal )
2242
+ self .nonnum = re .compile (
2243
+ '[^-^0-9^{decimal}]+' .format (decimal = self .decimal ))
2240
2244
else :
2241
- self .nonnum = re .compile ('[^-^0-9^%s^%s ]+' % ( self . thousands ,
2242
- self .decimal ))
2245
+ self .nonnum = re .compile ('[^-^0-9^{thousands}^{decimal} ]+' . format (
2246
+ thousands = self . thousands , decimal = self .decimal ))
2243
2247
2244
2248
def _set_no_thousands_columns (self ):
2245
2249
# Create a set of column ids that are not to be stripped of thousands
@@ -2478,8 +2482,8 @@ def _infer_columns(self):
2478
2482
except StopIteration :
2479
2483
if self .line_pos < hr :
2480
2484
raise ValueError (
2481
- 'Passed header=%s but only %d lines in file '
2482
- % (hr , self .line_pos + 1 ))
2485
+ 'Passed header={hr} but only {pos} lines in '
2486
+ 'file' . format (hr = hr , pos = ( self .line_pos + 1 ) ))
2483
2487
2484
2488
# We have an empty file, so check
2485
2489
# if columns are provided. That will
@@ -2520,7 +2524,8 @@ def _infer_columns(self):
2520
2524
2521
2525
while cur_count > 0 :
2522
2526
counts [col ] = cur_count + 1
2523
- col = "%s.%d" % (col , cur_count )
2527
+ col = "{columns}.{count}" .format (
2528
+ columns = col , count = cur_count )
2524
2529
cur_count = counts [col ]
2525
2530
2526
2531
this_columns [i ] = col
@@ -2588,8 +2593,8 @@ def _infer_columns(self):
2588
2593
2589
2594
if not names :
2590
2595
if self .prefix :
2591
- columns = [['%s%d' % ( self . prefix , i )
2592
- for i in range (ncols )]]
2596
+ columns = [['{prefix}{idx}' . format (
2597
+ prefix = self . prefix , idx = i ) for i in range (ncols )]]
2593
2598
else :
2594
2599
columns = [lrange (ncols )]
2595
2600
columns = self ._handle_usecols (columns , columns [0 ])
@@ -3016,8 +3021,9 @@ def _rows_to_cols(self, content):
3016
3021
content .append (l )
3017
3022
3018
3023
for row_num , actual_len in bad_lines :
3019
- msg = ('Expected %d fields in line %d, saw %d' %
3020
- (col_len , row_num + 1 , actual_len ))
3024
+ msg = ('Expected {col_len} fields in line {line}, saw '
3025
+ '{length}' .format (col_len = col_len , line = (row_num + 1 ),
3026
+ length = actual_len ))
3021
3027
if (self .delimiter and
3022
3028
len (self .delimiter ) > 1 and
3023
3029
self .quoting != csv .QUOTE_NONE ):
@@ -3188,8 +3194,9 @@ def _isindex(colspec):
3188
3194
new_name , col , old_names = _try_convert_dates (
3189
3195
converter , colspec , data_dict , orig_names )
3190
3196
if new_name in data_dict :
3191
- raise ValueError ('New date column already in dict %s' %
3192
- new_name )
3197
+ raise ValueError (
3198
+ 'New date column already in dict {name}' .format (
3199
+ name = new_name ))
3193
3200
new_data [new_name ] = col
3194
3201
new_cols .append (new_name )
3195
3202
date_cols .update (old_names )
@@ -3198,8 +3205,8 @@ def _isindex(colspec):
3198
3205
# dict of new name to column list
3199
3206
for new_name , colspec in compat .iteritems (parse_spec ):
3200
3207
if new_name in data_dict :
3201
- raise ValueError ('Date column %s already in dict' %
3202
- new_name )
3208
+ raise ValueError (
3209
+ 'Date column {name} already in dict' . format ( name = new_name ) )
3203
3210
3204
3211
_ , col , old_names = _try_convert_dates (converter , colspec ,
3205
3212
data_dict , orig_names )
@@ -3378,7 +3385,7 @@ def _stringify_na_values(na_values):
3378
3385
# we are like 999 here
3379
3386
if v == int (v ):
3380
3387
v = int (v )
3381
- result .append ("%s .0" % v )
3388
+ result .append ("{value} .0" . format ( value = v ) )
3382
3389
result .append (str (v ))
3383
3390
3384
3391
result .append (v )
@@ -3523,8 +3530,8 @@ def get_rows(self, infer_nrows, skiprows=None):
3523
3530
3524
3531
def detect_colspecs (self , infer_nrows = 100 , skiprows = None ):
3525
3532
# Regex escape the delimiters
3526
- delimiters = '' .join (r'\%s' % x for x in self .delimiter )
3527
- pattern = re .compile ('([^%s ]+)' % delimiters )
3533
+ delimiters = '' .join (r'\{}' . format ( x for x in self .delimiter ) )
3534
+ pattern = re .compile ('([^{} ]+)' . format ( delimiters ) )
3528
3535
rows = self .get_rows (infer_nrows , skiprows )
3529
3536
if not rows :
3530
3537
raise EmptyDataError ("No rows from which to infer column width" )
0 commit comments