@@ -589,8 +589,7 @@ cdef class TextReader:
589
589
590
590
if not isinstance (quote_char, (str , bytes)) and quote_char is not None :
591
591
dtype = type (quote_char).__name__
592
- raise TypeError (' "quotechar" must be string, '
593
- ' not {dtype}' .format(dtype = dtype))
592
+ raise TypeError (f' "quotechar" must be string, not {dtype}' )
594
593
595
594
if quote_char is None or quote_char == ' ' :
596
595
if quoting != QUOTE_NONE:
@@ -685,7 +684,7 @@ cdef class TextReader:
685
684
if not os.path.exists(source):
686
685
raise FileNotFoundError(
687
686
ENOENT,
688
- ' File {source} does not exist' .format( source = source) ,
687
+ f ' File {source} does not exist' ,
689
688
source)
690
689
raise IOError (' Initializing from file failed' )
691
690
@@ -741,8 +740,8 @@ cdef class TextReader:
741
740
self .parser.lines < hr):
742
741
msg = self .orig_header
743
742
if isinstance (msg, list ):
744
- msg = " [ %s ], len of %d , " % (
745
- ' , ' .join( str (m) for m in msg), len (msg))
743
+ joined = ' , ' .join( str (m) for m in msg)
744
+ msg = f " [{joined}], len of { len(msg)}, "
746
745
raise ParserError(
747
746
f' Passed header={msg} but only '
748
747
f' {self.parser.lines} lines in file' )
@@ -768,10 +767,9 @@ cdef class TextReader:
768
767
769
768
if name == ' ' :
770
769
if self .has_mi_columns:
771
- name = (' Unnamed: {i}_level_{lvl}'
772
- .format(i = i, lvl = level))
770
+ name = f' Unnamed: {i}_level_{level}'
773
771
else :
774
- name = ' Unnamed: {i}' .format( i = i)
772
+ name = f ' Unnamed: {i}'
775
773
unnamed_count += 1
776
774
777
775
count = counts.get(name, 0 )
@@ -990,7 +988,7 @@ cdef class TextReader:
990
988
cdef _end_clock(self , what):
991
989
if self .verbose:
992
990
elapsed = time.time() - self .clocks.pop(- 1 )
993
- print (' %s took: %.2f ms ' % (what, elapsed * 1000 ) )
991
+ print (f ' {what} took: { elapsed * 1000:.2f} ms ' )
994
992
995
993
def set_noconvert (self , i ):
996
994
self .noconvert.add(i)
@@ -1028,11 +1026,9 @@ cdef class TextReader:
1028
1026
(num_cols >= self .parser.line_fields[i]) * num_cols
1029
1027
1030
1028
if self .table_width - self .leading_cols > num_cols:
1031
- raise ParserError(
1032
- " Too many columns specified: expected {expected} and "
1033
- " found {found}"
1034
- .format(expected = self .table_width - self .leading_cols,
1035
- found = num_cols))
1029
+ raise ParserError(f" Too many columns specified: expected "
1030
+ f" {self.table_width - self.leading_cols} "
1031
+ f" and found {num_cols}" )
1036
1032
1037
1033
results = {}
1038
1034
nused = 0
@@ -1075,9 +1071,9 @@ cdef class TextReader:
1075
1071
1076
1072
if conv:
1077
1073
if col_dtype is not None :
1078
- warnings.warn((" Both a converter and dtype were specified "
1079
- " for column {0 } - only the converter will "
1080
- " be used" ).format(name ), ParserWarning,
1074
+ warnings.warn((f " Both a converter and dtype were specified "
1075
+ f " for column {name } - only the converter will "
1076
+ f " be used" ), ParserWarning,
1081
1077
stacklevel = 5 )
1082
1078
results[i] = _apply_converter(conv, self .parser, i, start, end,
1083
1079
self .c_encoding)
@@ -1118,7 +1114,7 @@ cdef class TextReader:
1118
1114
col_res = _maybe_upcast(col_res)
1119
1115
1120
1116
if col_res is None :
1121
- raise ParserError(' Unable to parse column {i}' .format( i = i) )
1117
+ raise ParserError(f ' Unable to parse column {i}' )
1122
1118
1123
1119
results[i] = col_res
1124
1120
@@ -1178,12 +1174,9 @@ cdef class TextReader:
1178
1174
col_res = col_res.astype(col_dtype)
1179
1175
if (col_res != col_res_orig).any():
1180
1176
raise ValueError (
1181
- " cannot safely convert passed user dtype of "
1182
- " {col_dtype} for {col_res} dtyped data in "
1183
- " column {column}" .format(
1184
- col_dtype = col_dtype,
1185
- col_res = col_res_orig.dtype.name,
1186
- column = i))
1177
+ f" cannot safely convert passed user dtype of "
1178
+ f" {col_dtype} for {col_res_orig.dtype.name} dtyped data in "
1179
+ f" column {i}" )
1187
1180
1188
1181
return col_res, na_count
1189
1182
@@ -1216,9 +1209,9 @@ cdef class TextReader:
1216
1209
dtype = dtype)
1217
1210
except NotImplementedError :
1218
1211
raise NotImplementedError (
1219
- " Extension Array: {ea } must implement "
1220
- " _from_sequence_of_strings in order "
1221
- " to be used in parser methods" .format( ea = array_type) )
1212
+ f " Extension Array: {array_type } must implement "
1213
+ f " _from_sequence_of_strings in order "
1214
+ f " to be used in parser methods" )
1222
1215
1223
1216
return result, na_count
1224
1217
@@ -1228,8 +1221,7 @@ cdef class TextReader:
1228
1221
end, na_filter, na_hashset)
1229
1222
if user_dtype and na_count is not None :
1230
1223
if na_count > 0 :
1231
- raise ValueError (" Integer column has NA values in "
1232
- " column {column}" .format(column = i))
1224
+ raise ValueError (f" Integer column has NA values in column {i}" )
1233
1225
except OverflowError :
1234
1226
result = _try_uint64(self .parser, i, start, end,
1235
1227
na_filter, na_hashset)
@@ -1253,8 +1245,7 @@ cdef class TextReader:
1253
1245
self .true_set, self .false_set)
1254
1246
if user_dtype and na_count is not None :
1255
1247
if na_count > 0 :
1256
- raise ValueError (" Bool column has NA values in "
1257
- " column {column}" .format(column = i))
1248
+ raise ValueError (f" Bool column has NA values in column {i}" )
1258
1249
return result, na_count
1259
1250
1260
1251
elif dtype.kind == ' S' :
@@ -1270,8 +1261,7 @@ cdef class TextReader:
1270
1261
elif dtype.kind == ' U' :
1271
1262
width = dtype.itemsize
1272
1263
if width > 0 :
1273
- raise TypeError (" the dtype {dtype} is not "
1274
- " supported for parsing" .format(dtype = dtype))
1264
+ raise TypeError (f" the dtype {dtype} is not supported for parsing" )
1275
1265
1276
1266
# unicode variable width
1277
1267
return self ._string_convert(i, start, end, na_filter,
@@ -1280,12 +1270,11 @@ cdef class TextReader:
1280
1270
return self ._string_convert(i, start, end, na_filter,
1281
1271
na_hashset)
1282
1272
elif is_datetime64_dtype(dtype):
1283
- raise TypeError (" the dtype {dtype} is not supported "
1284
- " for parsing, pass this column "
1285
- " using parse_dates instead" .format( dtype = dtype) )
1273
+ raise TypeError (f " the dtype {dtype} is not supported "
1274
+ f " for parsing, pass this column "
1275
+ f " using parse_dates instead" )
1286
1276
else :
1287
- raise TypeError (" the dtype {dtype} is not "
1288
- " supported for parsing" .format(dtype = dtype))
1277
+ raise TypeError (f" the dtype {dtype} is not supported for parsing" )
1289
1278
1290
1279
cdef _string_convert(self , Py_ssize_t i, int64_t start, int64_t end,
1291
1280
bint na_filter, kh_str_starts_t * na_hashset):
@@ -2132,7 +2121,7 @@ cdef raise_parser_error(object base, parser_t *parser):
2132
2121
Py_XDECREF(type )
2133
2122
raise old_exc
2134
2123
2135
- message = ' {base}. C error: ' .format( base = base)
2124
+ message = f ' {base}. C error: '
2136
2125
if parser.error_msg != NULL :
2137
2126
message += parser.error_msg.decode(' utf-8' )
2138
2127
else :
0 commit comments