-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Add extra check for failing UTF-8 conversion #32548
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
Merged
WillAyd
merged 5 commits into
pandas-dev:master
from
roberthdevries:fix-23809-read_excel-crashes-high-surrogate
Mar 12, 2020
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6bb3f9
Add extra check for failing UTF-8 conversion
roberthdevries a53e2f0
Reformatted by black
roberthdevries dc777e5
Add whatsnew entry
roberthdevries 6612801
Remove setting the exception, does not seem to be needed
roberthdevries 62b0cd5
Add check for expected output
roberthdevries File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1044,3 +1044,9 @@ def test_excel_read_binary(self, engine, read_ext): | |
|
||
actual = pd.read_excel(data, engine=engine) | ||
tm.assert_frame_equal(expected, actual) | ||
|
||
def test_excel_high_surrogate(self, read_ext): | ||
# GH 23809 | ||
|
||
# should not produce a segmentation violation | ||
pd.read_excel("high_surrogate.xlsx") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you create the expected dataframe and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to set the error here? I think the previous call would already set and can just return, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently the 'str' object passed is a Unicode type or a subtype. Ref: https://docs.python.org/3/c-api/unicode.html
And it seems to pass that test fine. However, it fails to convert to UTF8, hence the NULL return value.
BTW, I see know that the message is wrong (decode->encode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me clarify - so I am asking if you need the PyErr_SetString at all. I think the failing PyUnicode_AsUTF8String call should have already set the global error indicator / message, so I think this is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
I tried to figure out if
PyUnicode_AsUTF8String
sets an exception or not, but I failed to find out.However a manual test showed an exception so I guess we are covered here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea that's generally the pattern for the C API functions. Quoting the guide with respect to the global error indicator:
https://docs.python.org/3/c-api/exceptions.html#exception-handling
I'm not sure which ones don't fall into the "Most" category, but good to know this one does