@@ -1482,9 +1482,9 @@ def extract(r):
1482
1482
for n in range (len (columns [0 ])):
1483
1483
if all (compat .to_str (c [n ]) in self .unnamed_cols for c in columns ):
1484
1484
raise ParserError (
1485
- "Passed header=[%s ] are too many rows for this "
1485
+ "Passed header=[{header} ] are too many rows for this "
1486
1486
"multi_index of columns"
1487
- % ',' .join (str (x ) for x in self .header )
1487
+ . format ( header = ',' .join (str (x ) for x in self .header ) )
1488
1488
)
1489
1489
1490
1490
# Clean the column names (if we have an index_col).
@@ -1517,9 +1517,11 @@ def _maybe_dedup_names(self, names):
1517
1517
counts [col ] = cur_count + 1
1518
1518
1519
1519
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 ),)
1521
1522
else :
1522
- col = '%s.%d' % (col , cur_count )
1523
+ col = '{column}.{count}' .format (
1524
+ column = col , count = cur_count )
1523
1525
cur_count = counts [col ]
1524
1526
1525
1527
names [i ] = col
@@ -1566,7 +1568,7 @@ def _get_simple_index(self, data, columns):
1566
1568
def ix (col ):
1567
1569
if not isinstance (col , compat .string_types ):
1568
1570
return col
1569
- raise ValueError ('Index %s invalid' % col )
1571
+ raise ValueError ('Index {col} invalid' . format ( col = col ) )
1570
1572
1571
1573
to_remove = []
1572
1574
index = []
@@ -1590,8 +1592,8 @@ def _get_name(icol):
1590
1592
return icol
1591
1593
1592
1594
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 ))
1595
1597
1596
1598
for i , c in enumerate (col_names ):
1597
1599
if i == icol :
@@ -1706,7 +1708,8 @@ def _convert_to_ndarrays(self, dct, na_values, na_fvalues, verbose=False,
1706
1708
1707
1709
result [c ] = cvals
1708
1710
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 ))
1710
1713
return result
1711
1714
1712
1715
def _infer_types (self , values , na_values , try_num_bool = True ):
@@ -1807,8 +1810,10 @@ def _cast_types(self, values, cast_type, column):
1807
1810
values = astype_nansafe (values , cast_type ,
1808
1811
copy = True , skipna = True )
1809
1812
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 ))
1812
1817
return values
1813
1818
1814
1819
def _do_date_conversions (self , names , data ):
@@ -1871,7 +1876,7 @@ def __init__(self, src, **kwds):
1871
1876
1872
1877
if self .names is None :
1873
1878
if self .prefix :
1874
- self .names = ['%s%d' % ( self .prefix , i )
1879
+ self .names = ['{prefix}{i}' . format ( prefix = self .prefix , i = i )
1875
1880
for i in range (self ._reader .table_width )]
1876
1881
else :
1877
1882
self .names = lrange (self ._reader .table_width )
@@ -2273,10 +2278,11 @@ def __init__(self, f, **kwds):
2273
2278
raise ValueError ('Only length-1 decimal markers supported' )
2274
2279
2275
2280
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 ))
2277
2283
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 ))
2280
2286
2281
2287
def _set_no_thousands_columns (self ):
2282
2288
# Create a set of column ids that are not to be stripped of thousands
@@ -2515,8 +2521,8 @@ def _infer_columns(self):
2515
2521
except StopIteration :
2516
2522
if self .line_pos < hr :
2517
2523
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 ) ))
2520
2526
2521
2527
# We have an empty file, so check
2522
2528
# if columns are provided. That will
@@ -2557,7 +2563,8 @@ def _infer_columns(self):
2557
2563
2558
2564
while cur_count > 0 :
2559
2565
counts [col ] = cur_count + 1
2560
- col = "%s.%d" % (col , cur_count )
2566
+ col = u'{column}.{count}' .format (
2567
+ column = col , count = cur_count )
2561
2568
cur_count = counts [col ]
2562
2569
2563
2570
this_columns [i ] = col
@@ -2625,8 +2632,8 @@ def _infer_columns(self):
2625
2632
2626
2633
if not names :
2627
2634
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 )]]
2630
2637
else :
2631
2638
columns = [lrange (ncols )]
2632
2639
columns = self ._handle_usecols (columns , columns [0 ])
@@ -3053,8 +3060,9 @@ def _rows_to_cols(self, content):
3053
3060
content .append (l )
3054
3061
3055
3062
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 ))
3058
3066
if (self .delimiter and
3059
3067
len (self .delimiter ) > 1 and
3060
3068
self .quoting != csv .QUOTE_NONE ):
@@ -3225,8 +3233,9 @@ def _isindex(colspec):
3225
3233
new_name , col , old_names = _try_convert_dates (
3226
3234
converter , colspec , data_dict , orig_names )
3227
3235
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 ))
3230
3239
new_data [new_name ] = col
3231
3240
new_cols .append (new_name )
3232
3241
date_cols .update (old_names )
@@ -3235,8 +3244,8 @@ def _isindex(colspec):
3235
3244
# dict of new name to column list
3236
3245
for new_name , colspec in compat .iteritems (parse_spec ):
3237
3246
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 ) )
3240
3249
3241
3250
_ , col , old_names = _try_convert_dates (converter , colspec ,
3242
3251
data_dict , orig_names )
@@ -3415,7 +3424,7 @@ def _stringify_na_values(na_values):
3415
3424
# we are like 999 here
3416
3425
if v == int (v ):
3417
3426
v = int (v )
3418
- result .append ("%s .0" % v )
3427
+ result .append ("{value} .0" . format ( value = v ) )
3419
3428
result .append (str (v ))
3420
3429
3421
3430
result .append (v )
@@ -3560,8 +3569,8 @@ def get_rows(self, infer_nrows, skiprows=None):
3560
3569
3561
3570
def detect_colspecs (self , infer_nrows = 100 , skiprows = None ):
3562
3571
# 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 ) )
3565
3574
rows = self .get_rows (infer_nrows , skiprows )
3566
3575
if not rows :
3567
3576
raise EmptyDataError ("No rows from which to infer column width" )
0 commit comments