@@ -381,9 +381,7 @@ def _validate_integer(name, val, min_val=0):
381
381
min_val : int
382
382
Minimum allowed value (val < min_val will result in a ValueError)
383
383
"""
384
- msg = "'{name:s}' must be an integer >={min_val:d}" .format (
385
- name = name , min_val = min_val
386
- )
384
+ msg = f"'{ name :s} ' must be an integer >={ min_val :d} "
387
385
388
386
if val is not None :
389
387
if is_float (val ):
@@ -822,11 +820,7 @@ def __init__(self, f, engine=None, **kwds):
822
820
try :
823
821
dialect_val = getattr (dialect , param )
824
822
except AttributeError :
825
- raise ValueError (
826
- "Invalid dialect '{dialect}' provided" .format (
827
- dialect = kwds ["dialect" ]
828
- )
829
- )
823
+ raise ValueError (f"Invalid dialect { kwds ['dialect' ]} provided" )
830
824
parser_default = _parser_defaults [param ]
831
825
provided = kwds .get (param , parser_default )
832
826
@@ -838,11 +832,9 @@ def __init__(self, f, engine=None, **kwds):
838
832
# even if it conflicts with the dialect (gh-23761).
839
833
if provided != parser_default and provided != dialect_val :
840
834
msg = (
841
- "Conflicting values for '{param}': '{val}' was "
842
- "provided, but the dialect specifies '{diaval}'. "
843
- "Using the dialect-specified value." .format (
844
- param = param , val = provided , diaval = dialect_val
845
- )
835
+ f"Conflicting values for '{ param } ': '{ provided } ' was "
836
+ f"provided, but the dialect specifies '{ dialect_val } '. "
837
+ "Using the dialect-specified value."
846
838
)
847
839
848
840
# Annoying corner case for not warning about
@@ -993,9 +985,9 @@ def _clean_options(self, options, engine):
993
985
encodeable = False
994
986
if not encodeable and engine not in ("python" , "python-fwf" ):
995
987
fallback_reason = (
996
- "the separator encoded in {encoding} "
988
+ f "the separator encoded in { encoding } "
997
989
"is > 1 char long, and the 'c' engine "
998
- "does not support such separators" . format ( encoding = encoding )
990
+ "does not support such separators"
999
991
)
1000
992
engine = "python"
1001
993
@@ -1025,19 +1017,19 @@ def _clean_options(self, options, engine):
1025
1017
for arg in _python_unsupported :
1026
1018
if fallback_reason and result [arg ] != _c_parser_defaults [arg ]:
1027
1019
raise ValueError (
1028
- f "Falling back to the 'python' engine because "
1020
+ "Falling back to the 'python' engine because "
1029
1021
f"{ fallback_reason } , but this causes { repr (arg )} to be "
1030
- f "ignored as it is not supported by the 'python' engine."
1022
+ "ignored as it is not supported by the 'python' engine."
1031
1023
)
1032
1024
del result [arg ]
1033
1025
1034
1026
if fallback_reason :
1035
1027
warnings .warn (
1036
1028
(
1037
1029
"Falling back to the 'python' engine because "
1038
- "{0 }; you can avoid this warning by specifying "
1030
+ f" { fallback_reason } ; you can avoid this warning by specifying "
1039
1031
"engine='python'."
1040
- ). format ( fallback_reason ) ,
1032
+ ),
1041
1033
ParserWarning ,
1042
1034
stacklevel = 5 ,
1043
1035
)
@@ -1058,7 +1050,7 @@ def _clean_options(self, options, engine):
1058
1050
1059
1051
msg = (
1060
1052
f"The { repr (arg )} argument has been deprecated and will be "
1061
- f "removed in a future version."
1053
+ "removed in a future version."
1062
1054
)
1063
1055
1064
1056
if result .get (arg , depr_default ) != depr_default :
@@ -1128,9 +1120,9 @@ def _make_engine(self, engine="c"):
1128
1120
klass = FixedWidthFieldParser
1129
1121
else :
1130
1122
raise ValueError (
1131
- "Unknown engine: {engine} (valid options are"
1123
+ f "Unknown engine: { engine } (valid options are"
1132
1124
' "c", "python", or'
1133
- ' "python-fwf")' . format ( engine = engine )
1125
+ ' "python-fwf")'
1134
1126
)
1135
1127
self ._engine = klass (self .f , ** self .options )
1136
1128
@@ -1240,7 +1232,7 @@ def _validate_usecols_names(usecols, names):
1240
1232
if len (missing ) > 0 :
1241
1233
raise ValueError (
1242
1234
"Usecols do not match columns, "
1243
- "columns expected but not found: {missing}" . format ( missing = missing )
1235
+ f "columns expected but not found: { missing } "
1244
1236
)
1245
1237
1246
1238
return usecols
@@ -1541,11 +1533,9 @@ def _maybe_dedup_names(self, names):
1541
1533
counts [col ] = cur_count + 1
1542
1534
1543
1535
if is_potential_mi :
1544
- col = col [:- 1 ] + (
1545
- "{column}.{count}" .format (column = col [- 1 ], count = cur_count ),
1546
- )
1536
+ col = col [:- 1 ] + (f"{ col [- 1 ]} .{ cur_count } " ,)
1547
1537
else :
1548
- col = "{column }.{count}" . format ( column = col , count = cur_count )
1538
+ col = f" { col } .{ cur_count } "
1549
1539
cur_count = counts [col ]
1550
1540
1551
1541
names [i ] = col
@@ -1591,7 +1581,7 @@ def _get_simple_index(self, data, columns):
1591
1581
def ix (col ):
1592
1582
if not isinstance (col , str ):
1593
1583
return col
1594
- raise ValueError ("Index {col} invalid" . format ( col = col ) )
1584
+ raise ValueError (f "Index { col } invalid" )
1595
1585
1596
1586
to_remove = []
1597
1587
index = []
@@ -1615,11 +1605,7 @@ def _get_name(icol):
1615
1605
return icol
1616
1606
1617
1607
if col_names is None :
1618
- raise ValueError (
1619
- ("Must supply column order to use {icol!s} as index" ).format (
1620
- icol = icol
1621
- )
1622
- )
1608
+ raise ValueError (f"Must supply column order to use { icol !s} as index" )
1623
1609
1624
1610
for i , c in enumerate (col_names ):
1625
1611
if i == icol :
@@ -1695,9 +1681,9 @@ def _convert_to_ndarrays(
1695
1681
warnings .warn (
1696
1682
(
1697
1683
"Both a converter and dtype were specified "
1698
- "for column {0 } - only the converter will "
1684
+ f "for column { c } - only the converter will "
1699
1685
"be used"
1700
- ). format ( c ) ,
1686
+ ),
1701
1687
ParserWarning ,
1702
1688
stacklevel = 7 ,
1703
1689
)
@@ -1735,22 +1721,15 @@ def _convert_to_ndarrays(
1735
1721
and not is_categorical_dtype (cast_type )
1736
1722
and na_count > 0
1737
1723
):
1738
- raise ValueError (
1739
- "Bool column has NA values in "
1740
- "column {column}" .format (column = c )
1741
- )
1724
+ raise ValueError (f"Bool column has NA values in column { c } " )
1742
1725
except (AttributeError , TypeError ):
1743
1726
# invalid input to is_bool_dtype
1744
1727
pass
1745
1728
cvals = self ._cast_types (cvals , cast_type , c )
1746
1729
1747
1730
result [c ] = cvals
1748
1731
if verbose and na_count :
1749
- print (
1750
- "Filled {count} NA values in column {c!s}" .format (
1751
- count = na_count , c = c
1752
- )
1753
- )
1732
+ print (f"Filled { na_count } NA values in column { c !s} " )
1754
1733
return result
1755
1734
1756
1735
def _infer_types (self , values , na_values , try_num_bool = True ):
@@ -1847,18 +1826,17 @@ def _cast_types(self, values, cast_type, column):
1847
1826
return array_type ._from_sequence_of_strings (values , dtype = cast_type )
1848
1827
except NotImplementedError :
1849
1828
raise NotImplementedError (
1850
- "Extension Array: {ea } must implement "
1829
+ f "Extension Array: { array_type } must implement "
1851
1830
"_from_sequence_of_strings in order "
1852
- "to be used in parser methods" . format ( ea = array_type )
1831
+ "to be used in parser methods"
1853
1832
)
1854
1833
1855
1834
else :
1856
1835
try :
1857
1836
values = astype_nansafe (values , cast_type , copy = True , skipna = True )
1858
1837
except ValueError :
1859
1838
raise ValueError (
1860
- "Unable to convert column {column} to type "
1861
- "{cast_type}" .format (column = column , cast_type = cast_type )
1839
+ f"Unable to convert column { column } to type { cast_type } "
1862
1840
)
1863
1841
return values
1864
1842
@@ -1929,8 +1907,7 @@ def __init__(self, src, **kwds):
1929
1907
if self .names is None :
1930
1908
if self .prefix :
1931
1909
self .names = [
1932
- "{prefix}{i}" .format (prefix = self .prefix , i = i )
1933
- for i in range (self ._reader .table_width )
1910
+ f"{ self .prefix } { i } " for i in range (self ._reader .table_width )
1934
1911
]
1935
1912
else :
1936
1913
self .names = list (range (self ._reader .table_width ))
@@ -2345,15 +2322,9 @@ def __init__(self, f, **kwds):
2345
2322
raise ValueError ("Only length-1 decimal markers supported" )
2346
2323
2347
2324
if self .thousands is None :
2348
- self .nonnum = re .compile (
2349
- r"[^-^0-9^{decimal}]+" .format (decimal = self .decimal )
2350
- )
2325
+ self .nonnum = re .compile (fr"[^-^0-9^{ self .decimal } ]+" )
2351
2326
else :
2352
- self .nonnum = re .compile (
2353
- r"[^-^0-9^{thousands}^{decimal}]+" .format (
2354
- thousands = self .thousands , decimal = self .decimal
2355
- )
2356
- )
2327
+ self .nonnum = re .compile (fr"[^-^0-9^{ self .thousands } ^{ self .decimal } ]+" )
2357
2328
2358
2329
def _set_no_thousands_columns (self ):
2359
2330
# Create a set of column ids that are not to be stripped of thousands
@@ -2589,8 +2560,8 @@ def _infer_columns(self):
2589
2560
except StopIteration :
2590
2561
if self .line_pos < hr :
2591
2562
raise ValueError (
2592
- "Passed header={hr} but only {pos } lines in "
2593
- "file" . format ( hr = hr , pos = ( self . line_pos + 1 ))
2563
+ f "Passed header={ hr } but only { self . line_pos + 1 } lines in "
2564
+ "file"
2594
2565
)
2595
2566
2596
2567
# We have an empty file, so check
@@ -2613,11 +2584,9 @@ def _infer_columns(self):
2613
2584
for i , c in enumerate (line ):
2614
2585
if c == "" :
2615
2586
if have_mi_columns :
2616
- col_name = "Unnamed: {i}_level_{level}" .format (
2617
- i = i , level = level
2618
- )
2587
+ col_name = f"Unnamed: { i } _level_{ level } "
2619
2588
else :
2620
- col_name = "Unnamed: {i}" . format ( i = i )
2589
+ col_name = f "Unnamed: { i } "
2621
2590
2622
2591
this_unnamed_cols .append (i )
2623
2592
this_columns .append (col_name )
@@ -2632,7 +2601,7 @@ def _infer_columns(self):
2632
2601
2633
2602
while cur_count > 0 :
2634
2603
counts [col ] = cur_count + 1
2635
- col = "{column }.{count}" . format ( column = col , count = cur_count )
2604
+ col = f" { col } .{ cur_count } "
2636
2605
cur_count = counts [col ]
2637
2606
2638
2607
this_columns [i ] = col
@@ -2697,12 +2666,7 @@ def _infer_columns(self):
2697
2666
2698
2667
if not names :
2699
2668
if self .prefix :
2700
- columns = [
2701
- [
2702
- "{prefix}{idx}" .format (prefix = self .prefix , idx = i )
2703
- for i in range (ncols )
2704
- ]
2705
- ]
2669
+ columns = [[f"{ self .prefix } { i } " for i in range (ncols )]]
2706
2670
else :
2707
2671
columns = [list (range (ncols ))]
2708
2672
columns = self ._handle_usecols (columns , columns [0 ])
@@ -2904,7 +2868,7 @@ def _alert_malformed(self, msg, row_num):
2904
2868
if self .error_bad_lines :
2905
2869
raise ParserError (msg )
2906
2870
elif self .warn_bad_lines :
2907
- base = "Skipping line {row_num}: " . format ( row_num = row_num )
2871
+ base = f "Skipping line { row_num } : "
2908
2872
sys .stderr .write (base + msg + "\n " )
2909
2873
2910
2874
def _next_iter_line (self , row_num ):
@@ -3128,10 +3092,8 @@ def _rows_to_cols(self, content):
3128
3092
3129
3093
for row_num , actual_len in bad_lines :
3130
3094
msg = (
3131
- "Expected {col_len} fields in line {line}, saw "
3132
- "{length}" .format (
3133
- col_len = col_len , line = (row_num + 1 ), length = actual_len
3134
- )
3095
+ f"Expected { col_len } fields in line { row_num + 1 } , saw "
3096
+ f"{ actual_len } "
3135
3097
)
3136
3098
if (
3137
3099
self .delimiter
@@ -3329,9 +3291,7 @@ def _isindex(colspec):
3329
3291
converter , colspec , data_dict , orig_names
3330
3292
)
3331
3293
if new_name in data_dict :
3332
- raise ValueError (
3333
- "New date column already in dict {name}" .format (name = new_name )
3334
- )
3294
+ raise ValueError (f"New date column already in dict { new_name } " )
3335
3295
new_data [new_name ] = col
3336
3296
new_cols .append (new_name )
3337
3297
date_cols .update (old_names )
@@ -3340,9 +3300,7 @@ def _isindex(colspec):
3340
3300
# dict of new name to column list
3341
3301
for new_name , colspec in parse_spec .items ():
3342
3302
if new_name in data_dict :
3343
- raise ValueError (
3344
- "Date column {name} already in dict" .format (name = new_name )
3345
- )
3303
+ raise ValueError (f"Date column { new_name } already in dict" )
3346
3304
3347
3305
_ , col , old_names = _try_convert_dates (
3348
3306
converter , colspec , data_dict , orig_names
@@ -3521,7 +3479,7 @@ def _stringify_na_values(na_values):
3521
3479
# we are like 999 here
3522
3480
if v == int (v ):
3523
3481
v = int (v )
3524
- result .append ("{value }.0". format ( value = v ) )
3482
+ result .append (f" { v } .0" )
3525
3483
result .append (str (v ))
3526
3484
3527
3485
result .append (v )
0 commit comments