@@ -1485,9 +1485,9 @@ def extract(r):
1485
1485
for n in range (len (columns [0 ])):
1486
1486
if all (compat .to_str (c [n ]) in self .unnamed_cols for c in columns ):
1487
1487
raise ParserError (
1488
- "Passed header=[%s ] are too many rows for this "
1488
+ "Passed header=[{header} ] are too many rows for this "
1489
1489
"multi_index of columns"
1490
- % ',' .join (str (x ) for x in self .header )
1490
+ . format ( header = ',' .join (str (x ) for x in self .header ) )
1491
1491
)
1492
1492
1493
1493
# Clean the column names (if we have an index_col).
@@ -1520,9 +1520,11 @@ def _maybe_dedup_names(self, names):
1520
1520
counts [col ] = cur_count + 1
1521
1521
1522
1522
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 ),)
1524
1525
else :
1525
- col = '%s.%d' % (col , cur_count )
1526
+ col = '{column}.{count}' .format (
1527
+ column = col , count = cur_count )
1526
1528
cur_count = counts [col ]
1527
1529
1528
1530
names [i ] = col
@@ -1569,7 +1571,7 @@ def _get_simple_index(self, data, columns):
1569
1571
def ix (col ):
1570
1572
if not isinstance (col , compat .string_types ):
1571
1573
return col
1572
- raise ValueError ('Index %s invalid' % col )
1574
+ raise ValueError ('Index {col} invalid' . format ( col = col ) )
1573
1575
1574
1576
to_remove = []
1575
1577
index = []
@@ -1593,8 +1595,8 @@ def _get_name(icol):
1593
1595
return icol
1594
1596
1595
1597
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 ))
1598
1600
1599
1601
for i , c in enumerate (col_names ):
1600
1602
if i == icol :
@@ -1709,7 +1711,8 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
1709
1711
1710
1712
result [c ] = cvals
1711
1713
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 ))
1713
1716
return result
1714
1717
1715
1718
def _infer_types (self , values , na_values , try_num_bool = True ):
@@ -1810,8 +1813,10 @@ def _cast_types(self, values, cast_type, column):
1810
1813
values = astype_nansafe (values , cast_type ,
1811
1814
copy = True , skipna = True )
1812
1815
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 ))
1815
1820
return values
1816
1821
1817
1822
def _do_date_conversions (self , names , data ):
@@ -1874,7 +1879,7 @@ def __init__(self, src, **kwds):
1874
1879
1875
1880
if self .names is None :
1876
1881
if self .prefix :
1877
- self .names = ['%s%d' % ( self .prefix , i )
1882
+ self .names = ['{prefix}{i}' . format ( prefix = self .prefix , i = i )
1878
1883
for i in range (self ._reader .table_width )]
1879
1884
else :
1880
1885
self .names = lrange (self ._reader .table_width )
@@ -2276,10 +2281,11 @@ def __init__(self, f, **kwds):
2276
2281
raise ValueError ('Only length-1 decimal markers supported' )
2277
2282
2278
2283
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 ))
2280
2286
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 ))
2283
2289
2284
2290
def _set_no_thousands_columns (self ):
2285
2291
# Create a set of column ids that are not to be stripped of thousands
@@ -2518,8 +2524,8 @@ def _infer_columns(self):
2518
2524
except StopIteration :
2519
2525
if self .line_pos < hr :
2520
2526
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 ) ))
2523
2529
2524
2530
# We have an empty file, so check
2525
2531
# if columns are provided. That will
@@ -2560,7 +2566,8 @@ def _infer_columns(self):
2560
2566
2561
2567
while cur_count > 0 :
2562
2568
counts [col ] = cur_count + 1
2563
- col = "%s.%d" % (col , cur_count )
2569
+ col = '{column}.{count}' .format (
2570
+ column = col , count = cur_count )
2564
2571
cur_count = counts [col ]
2565
2572
2566
2573
this_columns [i ] = col
@@ -2628,8 +2635,8 @@ def _infer_columns(self):
2628
2635
2629
2636
if not names :
2630
2637
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 )]]
2633
2640
else :
2634
2641
columns = [lrange (ncols )]
2635
2642
columns = self ._handle_usecols (columns , columns [0 ])
@@ -3056,8 +3063,9 @@ def _rows_to_cols(self, content):
3056
3063
content .append (l )
3057
3064
3058
3065
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 ))
3061
3069
if (self .delimiter and
3062
3070
len (self .delimiter ) > 1 and
3063
3071
self .quoting != csv .QUOTE_NONE ):
@@ -3228,8 +3236,9 @@ def _isindex(colspec):
3228
3236
new_name , col , old_names = _try_convert_dates (
3229
3237
converter , colspec , data_dict , orig_names )
3230
3238
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 ))
3233
3242
new_data [new_name ] = col
3234
3243
new_cols .append (new_name )
3235
3244
date_cols .update (old_names )
@@ -3238,8 +3247,8 @@ def _isindex(colspec):
3238
3247
# dict of new name to column list
3239
3248
for new_name , colspec in compat .iteritems (parse_spec ):
3240
3249
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 ) )
3243
3252
3244
3253
_ , col , old_names = _try_convert_dates (converter , colspec ,
3245
3254
data_dict , orig_names )
@@ -3418,7 +3427,7 @@ def _stringify_na_values(na_values):
3418
3427
# we are like 999 here
3419
3428
if v == int (v ):
3420
3429
v = int (v )
3421
- result .append ("%s .0" % v )
3430
+ result .append ("{value} .0" . format ( value = v ) )
3422
3431
result .append (str (v ))
3423
3432
3424
3433
result .append (v )
@@ -3563,8 +3572,8 @@ def get_rows(self, infer_nrows, skiprows=None):
3563
3572
3564
3573
def detect_colspecs (self , infer_nrows = 100 , skiprows = None ):
3565
3574
# 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 ) )
3568
3577
rows = self .get_rows (infer_nrows , skiprows )
3569
3578
if not rows :
3570
3579
raise EmptyDataError ("No rows from which to infer column width" )
0 commit comments