@@ -1482,9 +1482,9 @@ def extract(r):
14821482 for n in range (len (columns [0 ])):
14831483 if all (compat .to_str (c [n ]) in self .unnamed_cols for c in columns ):
14841484 raise ParserError (
1485- "Passed header=[%s ] are too many rows for this "
1485+ "Passed header=[{header} ] are too many rows for this "
14861486 "multi_index of columns"
1487- % ',' .join (str (x ) for x in self .header )
1487+ . format ( header = ',' .join (str (x ) for x in self .header ) )
14881488 )
14891489
14901490 # Clean the column names (if we have an index_col).
@@ -1517,9 +1517,11 @@ def _maybe_dedup_names(self, names):
15171517 counts [col ] = cur_count + 1
15181518
15191519 if is_potential_mi :
1520- col = col [:- 1 ] + ('%s.%d' % (col [- 1 ], cur_count ),)
1520+ col = col [:- 1 ] + ('{column}.{count}' .format (
1521+ column = col [- 1 ], count = cur_count ),)
15211522 else :
1522- col = '%s.%d' % (col , cur_count )
1523+ col = '{column}.{count}' .format (
1524+ column = col , count = cur_count )
15231525 cur_count = counts [col ]
15241526
15251527 names [i ] = col
@@ -1566,7 +1568,7 @@ def _get_simple_index(self, data, columns):
15661568 def ix (col ):
15671569 if not isinstance (col , compat .string_types ):
15681570 return col
1569- raise ValueError ('Index %s invalid' % col )
1571+ raise ValueError ('Index {col} invalid' . format ( col = col ) )
15701572
15711573 to_remove = []
15721574 index = []
@@ -1590,8 +1592,8 @@ def _get_name(icol):
15901592 return icol
15911593
15921594 if col_names is None :
1593- raise ValueError (('Must supply column order to use %s as '
1594- 'index' ) % str ( icol ))
1595+ raise ValueError (('Must supply column order to use {icol!s} '
1596+ 'as index' ). format ( icol = icol ))
15951597
15961598 for i , c in enumerate (col_names ):
15971599 if i == icol :
@@ -1706,7 +1708,8 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
17061708
17071709 result [c ] = cvals
17081710 if verbose and na_count :
1709- print ('Filled %d NA values in column %s' % (na_count , str (c )))
1711+ print ('Filled {count} NA values in column {c!s}' .format (
1712+ count = na_count , c = c ))
17101713 return result
17111714
17121715 def _infer_types (self , values , na_values , try_num_bool = True ):
@@ -1807,8 +1810,10 @@ def _cast_types(self, values, cast_type, column):
18071810 values = astype_nansafe (values , cast_type ,
18081811 copy = True , skipna = True )
18091812 except ValueError :
1810- raise ValueError ("Unable to convert column %s to "
1811- "type %s" % (column , cast_type ))
1813+ raise ValueError (
1814+ "Unable to convert column {column} to type "
1815+ "{cast_type}" .format (
1816+ column = column , cast_type = cast_type ))
18121817 return values
18131818
18141819 def _do_date_conversions (self , names , data ):
@@ -1871,7 +1876,7 @@ def __init__(self, src, **kwds):
18711876
18721877 if self .names is None :
18731878 if self .prefix :
1874- self .names = ['%s%d' % ( self .prefix , i )
1879+ self .names = ['{prefix}{i}' . format ( prefix = self .prefix , i = i )
18751880 for i in range (self ._reader .table_width )]
18761881 else :
18771882 self .names = lrange (self ._reader .table_width )
@@ -2273,10 +2278,11 @@ def __init__(self, f, **kwds):
22732278 raise ValueError ('Only length-1 decimal markers supported' )
22742279
22752280 if self .thousands is None :
2276- self .nonnum = re .compile ('[^-^0-9^%s]+' % self .decimal )
2281+ self .nonnum = re .compile (
2282+ r'[^-^0-9^{decimal}]+' .format (decimal = self .decimal ))
22772283 else :
2278- self .nonnum = re .compile ('[^-^0-9^%s^%s ]+' % ( self . thousands ,
2279- self .decimal ))
2284+ self .nonnum = re .compile (r '[^-^0-9^{thousands}^{decimal} ]+'. format (
2285+ thousands = self . thousands , decimal = self .decimal ))
22802286
22812287 def _set_no_thousands_columns (self ):
22822288 # Create a set of column ids that are not to be stripped of thousands
@@ -2515,8 +2521,8 @@ def _infer_columns(self):
25152521 except StopIteration :
25162522 if self .line_pos < hr :
25172523 raise ValueError (
2518- 'Passed header=%s but only %d lines in file '
2519- % (hr , self .line_pos + 1 ))
2524+ 'Passed header={hr} but only {pos} lines in '
2525+ 'file' . format (hr = hr , pos = ( self .line_pos + 1 ) ))
25202526
25212527 # We have an empty file, so check
25222528 # if columns are provided. That will
@@ -2557,7 +2563,8 @@ def _infer_columns(self):
25572563
25582564 while cur_count > 0 :
25592565 counts [col ] = cur_count + 1
2560- col = "%s.%d" % (col , cur_count )
2566+ col = u'{column}.{count}' .format (
2567+ column = col , count = cur_count )
25612568 cur_count = counts [col ]
25622569
25632570 this_columns [i ] = col
@@ -2625,8 +2632,8 @@ def _infer_columns(self):
26252632
26262633 if not names :
26272634 if self .prefix :
2628- columns = [['%s%d' % ( self . prefix , i )
2629- for i in range (ncols )]]
2635+ columns = [['{prefix}{idx}' . format (
2636+ prefix = self . prefix , idx = i ) for i in range (ncols )]]
26302637 else :
26312638 columns = [lrange (ncols )]
26322639 columns = self ._handle_usecols (columns , columns [0 ])
@@ -3053,8 +3060,9 @@ def _rows_to_cols(self, content):
30533060 content .append (l )
30543061
30553062 for row_num , actual_len in bad_lines :
3056- msg = ('Expected %d fields in line %d, saw %d' %
3057- (col_len , row_num + 1 , actual_len ))
3063+ msg = ('Expected {col_len} fields in line {line}, saw '
3064+ '{length}' .format (col_len = col_len , line = (row_num + 1 ),
3065+ length = actual_len ))
30583066 if (self .delimiter and
30593067 len (self .delimiter ) > 1 and
30603068 self .quoting != csv .QUOTE_NONE ):
@@ -3225,8 +3233,9 @@ def _isindex(colspec):
32253233 new_name , col , old_names = _try_convert_dates (
32263234 converter , colspec , data_dict , orig_names )
32273235 if new_name in data_dict :
3228- raise ValueError ('New date column already in dict %s' %
3229- new_name )
3236+ raise ValueError (
3237+ 'New date column already in dict {name}' .format (
3238+ name = new_name ))
32303239 new_data [new_name ] = col
32313240 new_cols .append (new_name )
32323241 date_cols .update (old_names )
@@ -3235,8 +3244,8 @@ def _isindex(colspec):
32353244 # dict of new name to column list
32363245 for new_name , colspec in compat .iteritems (parse_spec ):
32373246 if new_name in data_dict :
3238- raise ValueError ('Date column %s already in dict' %
3239- new_name )
3247+ raise ValueError (
3248+ 'Date column {name} already in dict' . format ( name = new_name ) )
32403249
32413250 _ , col , old_names = _try_convert_dates (converter , colspec ,
32423251 data_dict , orig_names )
@@ -3415,7 +3424,7 @@ def _stringify_na_values(na_values):
34153424 # we are like 999 here
34163425 if v == int (v ):
34173426 v = int (v )
3418- result .append ("%s .0" % v )
3427+ result .append ("{value} .0" . format ( value = v ) )
34193428 result .append (str (v ))
34203429
34213430 result .append (v )
@@ -3560,8 +3569,8 @@ def get_rows(self, infer_nrows, skiprows=None):
35603569
35613570 def detect_colspecs (self , infer_nrows = 100 , skiprows = None ):
35623571 # Regex escape the delimiters
3563- delimiters = '' .join (r'\%s' % x for x in self .delimiter )
3564- pattern = re .compile ('([^%s ]+)' % delimiters )
3572+ delimiters = '' .join (r'\{}' . format ( x ) for x in self .delimiter )
3573+ pattern = re .compile ('([^{} ]+)' . format ( delimiters ) )
35653574 rows = self .get_rows (infer_nrows , skiprows )
35663575 if not rows :
35673576 raise EmptyDataError ("No rows from which to infer column width" )
0 commit comments