Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: F-strings #29870

Merged
merged 2 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/io/msgpack/_packer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ cdef class Packer:
default_used = 1
continue
else:
raise TypeError("can't serialize {thing!r}".format(thing=o))
raise TypeError(f"can't serialize {repr(o)}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason not to use the !r syntax?

Copy link
Member Author

@ShaharNaveh ShaharNaveh Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed pep-498 (!s, !r, and !a are redundant section).

Plus as someone who is new to python, at first I didn't understand the !r syntax. I do think that if we use repr() it will increase code readability (for new developers at least).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough but not seen this conversion in other PRs for #29547

to ensure consistency, could either update the issue with additional instructions or add a code check to disallow the redundant sytnax in f-strings (as a follow-on).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! love the idea of making a code style in the issue tab.

I don't have the confident to write this mini style guide, I really don't want to mislead people.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MomIsBestFriend ok if you'd make an issue about standarizing on repr(...) rather than !r agree that its more explicit; we would need to change any code and add a code-check.

break
return ret

Expand Down
7 changes: 3 additions & 4 deletions pandas/io/msgpack/_unpacker.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ cdef inline init_ctx(unpack_context *ctx,

def default_read_extended_type(typecode, data):
raise NotImplementedError("Cannot decode extended type "
"with typecode={code}".format(code=typecode))
f"with typecode={typecode}")


def unpackb(object packed, object object_hook=None, object list_hook=None,
Expand Down Expand Up @@ -159,7 +159,7 @@ def unpackb(object packed, object object_hook=None, object list_hook=None,
return obj
else:
PyBuffer_Release(&view)
raise UnpackValueError("Unpack failed: error = {ret}".format(ret=ret))
raise UnpackValueError(f"Unpack failed: error = {ret}")


def unpack(object stream, object object_hook=None, object list_hook=None,
Expand Down Expand Up @@ -430,8 +430,7 @@ cdef class Unpacker:
else:
raise OutOfData("No more data to unpack.")
else:
raise ValueError("Unpack failed: error = {ret}"
.format(ret=ret))
raise ValueError(f"Unpack failed: error = {ret}")

def read_bytes(self, Py_ssize_t nbytes):
"""Read a specified number of raw bytes from the stream"""
Expand Down
15 changes: 5 additions & 10 deletions pandas/io/sas/sas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ cdef const uint8_t[:] rle_decompress(int result_length,
result[rpos] = 0x00
rpos += 1
else:
raise ValueError("unknown control byte: {byte}"
.format(byte=control_byte))
raise ValueError(f"unknown control byte: {control_byte}")

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

return np.asarray(result)

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

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

return np.asarray(outbuff)

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

# compression
if parser.compression == const.rle_compression:
Expand Down Expand Up @@ -392,8 +388,7 @@ cdef class Parser:
return True
return False
else:
raise ValueError("unknown page type: {typ}"
.format(typ=self.current_page_type))
raise ValueError(f"unknown page type: {self.current_page_type}")

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

Expand Down