Skip to content

Commit 99cf733

Browse files
ShaharNavehjreback
authored andcommitted
F-strings (#29870)
1 parent f855025 commit 99cf733

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

pandas/io/msgpack/_packer.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ cdef class Packer:
234234
default_used = 1
235235
continue
236236
else:
237-
raise TypeError("can't serialize {thing!r}".format(thing=o))
237+
raise TypeError(f"can't serialize {repr(o)}")
238238
break
239239
return ret
240240

pandas/io/msgpack/_unpacker.pyx

+3-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ cdef inline init_ctx(unpack_context *ctx,
9999

100100
def default_read_extended_type(typecode, data):
101101
raise NotImplementedError("Cannot decode extended type "
102-
"with typecode={code}".format(code=typecode))
102+
f"with typecode={typecode}")
103103

104104

105105
def unpackb(object packed, object object_hook=None, object list_hook=None,
@@ -159,7 +159,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
159159
return obj
160160
else:
161161
PyBuffer_Release(&view)
162-
raise UnpackValueError("Unpack failed: error = {ret}".format(ret=ret))
162+
raise UnpackValueError(f"Unpack failed: error = {ret}")
163163

164164

165165
def unpack(object stream, object object_hook=None, object list_hook=None,
@@ -430,8 +430,7 @@ cdef class Unpacker:
430430
else:
431431
raise OutOfData("No more data to unpack.")
432432
else:
433-
raise ValueError("Unpack failed: error = {ret}"
434-
.format(ret=ret))
433+
raise ValueError(f"Unpack failed: error = {ret}")
435434

436435
def read_bytes(self, Py_ssize_t nbytes):
437436
"""Read a specified number of raw bytes from the stream"""

pandas/io/sas/sas.pyx

+5-10
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,11 @@ cdef const uint8_t[:] rle_decompress(int result_length,
105105
result[rpos] = 0x00
106106
rpos += 1
107107
else:
108-
raise ValueError("unknown control byte: {byte}"
109-
.format(byte=control_byte))
108+
raise ValueError(f"unknown control byte: {control_byte}")
110109

111110
# In py37 cython/clang sees `len(outbuff)` as size_t and not Py_ssize_t
112111
if <Py_ssize_t>len(result) != <Py_ssize_t>result_length:
113-
raise ValueError("RLE: {got} != {expect}".format(got=len(result),
114-
expect=result_length))
112+
raise ValueError(f"RLE: {len(result)} != {result_length}")
115113

116114
return np.asarray(result)
117115

@@ -194,8 +192,7 @@ cdef const uint8_t[:] rdc_decompress(int result_length,
194192

195193
# In py37 cython/clang sees `len(outbuff)` as size_t and not Py_ssize_t
196194
if <Py_ssize_t>len(outbuff) != <Py_ssize_t>result_length:
197-
raise ValueError("RDC: {got} != {expect}\n"
198-
.format(got=len(outbuff), expect=result_length))
195+
raise ValueError(f"RDC: {len(outbuff)} != {result_length}\n")
199196

200197
return np.asarray(outbuff)
201198

@@ -271,8 +268,7 @@ cdef class Parser:
271268
self.column_types[j] = column_type_string
272269
else:
273270
raise ValueError("unknown column type: "
274-
"{typ}"
275-
.format(typ=self.parser.columns[j].ctype))
271+
f"{self.parser.columns[j].ctype}")
276272

277273
# compression
278274
if parser.compression == const.rle_compression:
@@ -392,8 +388,7 @@ cdef class Parser:
392388
return True
393389
return False
394390
else:
395-
raise ValueError("unknown page type: {typ}"
396-
.format(typ=self.current_page_type))
391+
raise ValueError(f"unknown page type: {self.current_page_type}")
397392

398393
cdef void process_byte_array_with_data(self, int offset, int length):
399394

0 commit comments

Comments
 (0)