@@ -1485,9 +1485,9 @@ def extract(r):
14851485 for n in range (len (columns [0 ])):
14861486 if all (compat .to_str (c [n ]) in self .unnamed_cols for c in columns ):
14871487 raise ParserError (
1488- "Passed header=[%s ] are too many rows for this "
1488+ "Passed header=[{header} ] are too many rows for this "
14891489 "multi_index of columns"
1490- % ',' .join (str (x ) for x in self .header )
1490+ . format ( header = ',' .join (str (x ) for x in self .header ) )
14911491 )
14921492
14931493 # Clean the column names (if we have an index_col).
@@ -1520,9 +1520,11 @@ def _maybe_dedup_names(self, names):
15201520 counts [col ] = cur_count + 1
15211521
15221522 if is_potential_mi :
1523- col = col [:- 1 ] + ('%s.%d' % (col [- 1 ], cur_count ),)
1523+ col = col [:- 1 ] + ('{column}.{count}' .format (
1524+ column = col [- 1 ], count = cur_count ),)
15241525 else :
1525- col = '%s.%d' % (col , cur_count )
1526+ col = '{column}.{count}' .format (
1527+ column = col , count = cur_count )
15261528 cur_count = counts [col ]
15271529
15281530 names [i ] = col
@@ -1569,7 +1571,7 @@ def _get_simple_index(self, data, columns):
15691571 def ix (col ):
15701572 if not isinstance (col , compat .string_types ):
15711573 return col
1572- raise ValueError ('Index %s invalid' % col )
1574+ raise ValueError ('Index {col} invalid' . format ( col = col ) )
15731575
15741576 to_remove = []
15751577 index = []
@@ -1593,8 +1595,8 @@ def _get_name(icol):
15931595 return icol
15941596
15951597 if col_names is None :
1596- raise ValueError (('Must supply column order to use %s as '
1597- 'index' ) % str ( icol ))
1598+ raise ValueError (('Must supply column order to use {icol!s} '
1599+ 'as index' ). format ( icol = icol ))
15981600
15991601 for i , c in enumerate (col_names ):
16001602 if i == icol :
@@ -1709,7 +1711,8 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
17091711
17101712 result [c ] = cvals
17111713 if verbose and na_count :
1712- print ('Filled %d NA values in column %s' % (na_count , str (c )))
1714+ print ('Filled {count} NA values in column {c!s}' .format (
1715+ count = na_count , c = c ))
17131716 return result
17141717
17151718 def _infer_types (self , values , na_values , try_num_bool = True ):
@@ -1810,8 +1813,10 @@ def _cast_types(self, values, cast_type, column):
18101813 values = astype_nansafe (values , cast_type ,
18111814 copy = True , skipna = True )
18121815 except ValueError :
1813- raise ValueError ("Unable to convert column %s to "
1814- "type %s" % (column , cast_type ))
1816+ raise ValueError (
1817+ "Unable to convert column {column} to type "
1818+ "{cast_type}" .format (
1819+ column = column , cast_type = cast_type ))
18151820 return values
18161821
18171822 def _do_date_conversions (self , names , data ):
@@ -1874,7 +1879,7 @@ def __init__(self, src, **kwds):
18741879
18751880 if self .names is None :
18761881 if self .prefix :
1877- self .names = ['%s%d' % ( self .prefix , i )
1882+ self .names = ['{prefix}{i}' . format ( prefix = self .prefix , i = i )
18781883 for i in range (self ._reader .table_width )]
18791884 else :
18801885 self .names = lrange (self ._reader .table_width )
@@ -2276,10 +2281,11 @@ def __init__(self, f, **kwds):
22762281 raise ValueError ('Only length-1 decimal markers supported' )
22772282
22782283 if self .thousands is None :
2279- self .nonnum = re .compile ('[^-^0-9^%s]+' % self .decimal )
2284+ self .nonnum = re .compile (
2285+ r'[^-^0-9^{decimal}]+' .format (decimal = self .decimal ))
22802286 else :
2281- self .nonnum = re .compile ('[^-^0-9^%s^%s ]+' % ( self . thousands ,
2282- self .decimal ))
2287+ self .nonnum = re .compile (r '[^-^0-9^{thousands}^{decimal} ]+'. format (
2288+ thousands = self . thousands , decimal = self .decimal ))
22832289
22842290 def _set_no_thousands_columns (self ):
22852291 # Create a set of column ids that are not to be stripped of thousands
@@ -2518,8 +2524,8 @@ def _infer_columns(self):
25182524 except StopIteration :
25192525 if self .line_pos < hr :
25202526 raise ValueError (
2521- 'Passed header=%s but only %d lines in file '
2522- % (hr , self .line_pos + 1 ))
2527+ 'Passed header={hr} but only {pos} lines in '
2528+ 'file' . format (hr = hr , pos = ( self .line_pos + 1 ) ))
25232529
25242530 # We have an empty file, so check
25252531 # if columns are provided. That will
@@ -2560,7 +2566,8 @@ def _infer_columns(self):
25602566
25612567 while cur_count > 0 :
25622568 counts [col ] = cur_count + 1
2563- col = "%s.%d" % (col , cur_count )
2569+ col = '{column}.{count}' .format (
2570+ column = col , count = cur_count )
25642571 cur_count = counts [col ]
25652572
25662573 this_columns [i ] = col
@@ -2628,8 +2635,8 @@ def _infer_columns(self):
26282635
26292636 if not names :
26302637 if self .prefix :
2631- columns = [['%s%d' % ( self . prefix , i )
2632- for i in range (ncols )]]
2638+ columns = [['{prefix}{idx}' . format (
2639+ prefix = self . prefix , idx = i ) for i in range (ncols )]]
26332640 else :
26342641 columns = [lrange (ncols )]
26352642 columns = self ._handle_usecols (columns , columns [0 ])
@@ -3056,8 +3063,9 @@ def _rows_to_cols(self, content):
30563063 content .append (l )
30573064
30583065 for row_num , actual_len in bad_lines :
3059- msg = ('Expected %d fields in line %d, saw %d' %
3060- (col_len , row_num + 1 , actual_len ))
3066+ msg = ('Expected {col_len} fields in line {line}, saw '
3067+ '{length}' .format (col_len = col_len , line = (row_num + 1 ),
3068+ length = actual_len ))
30613069 if (self .delimiter and
30623070 len (self .delimiter ) > 1 and
30633071 self .quoting != csv .QUOTE_NONE ):
@@ -3228,8 +3236,9 @@ def _isindex(colspec):
32283236 new_name , col , old_names = _try_convert_dates (
32293237 converter , colspec , data_dict , orig_names )
32303238 if new_name in data_dict :
3231- raise ValueError ('New date column already in dict %s' %
3232- new_name )
3239+ raise ValueError (
3240+ 'New date column already in dict {name}' .format (
3241+ name = new_name ))
32333242 new_data [new_name ] = col
32343243 new_cols .append (new_name )
32353244 date_cols .update (old_names )
@@ -3238,8 +3247,8 @@ def _isindex(colspec):
32383247 # dict of new name to column list
32393248 for new_name , colspec in compat .iteritems (parse_spec ):
32403249 if new_name in data_dict :
3241- raise ValueError ('Date column %s already in dict' %
3242- new_name )
3250+ raise ValueError (
3251+ 'Date column {name} already in dict' . format ( name = new_name ) )
32433252
32443253 _ , col , old_names = _try_convert_dates (converter , colspec ,
32453254 data_dict , orig_names )
@@ -3418,7 +3427,7 @@ def _stringify_na_values(na_values):
34183427 # we are like 999 here
34193428 if v == int (v ):
34203429 v = int (v )
3421- result .append ("%s .0" % v )
3430+ result .append ("{value} .0" . format ( value = v ) )
34223431 result .append (str (v ))
34233432
34243433 result .append (v )
@@ -3563,8 +3572,8 @@ def get_rows(self, infer_nrows, skiprows=None):
35633572
35643573 def detect_colspecs (self , infer_nrows = 100 , skiprows = None ):
35653574 # Regex escape the delimiters
3566- delimiters = '' .join (r'\%s' % x for x in self .delimiter )
3567- pattern = re .compile ('([^%s ]+)' % delimiters )
3575+ delimiters = '' .join (r'\{}' . format ( x ) for x in self .delimiter )
3576+ pattern = re .compile ('([^{} ]+)' . format ( delimiters ) )
35683577 rows = self .get_rows (infer_nrows , skiprows )
35693578 if not rows :
35703579 raise EmptyDataError ("No rows from which to infer column width" )
0 commit comments