-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Safely raise errors when object contains unicode #20593
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
jreback
merged 11 commits into
pandas-dev:master
from
janrito:bug/fix-assert-frame-equals-with-unicode-data
Apr 9, 2018
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9cd83ff
Safely raise errors when object contains unicode
janrito 46cadc0
Whatsnew entry
janrito 99ac0e8
Tests for comparisons of objects containing unicode
janrito 329002c
Only need to pprint with the display encoding
janrito b506cf6
Linting
janrito 8f607c3
Whatnew update
janrito 6b087f2
Separate tests and document gh issue
janrito 51366f2
Encode in utf-8 only in python2
janrito 575b2e8
import compat.PY2 and compat.string_types directly
janrito 45d2b8e
Added documenting comments
janrito 1f7e231
Add binary <-> unicode tests
janrito 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
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 |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
import pandas.compat as compat | ||
from pandas.compat import ( | ||
filter, map, zip, range, unichr, lrange, lmap, lzip, u, callable, Counter, | ||
raise_with_traceback, httplib, StringIO, PY3) | ||
raise_with_traceback, httplib, StringIO, string_types, PY3, PY2) | ||
|
||
from pandas import (bdate_range, CategoricalIndex, Categorical, IntervalIndex, | ||
DatetimeIndex, TimedeltaIndex, PeriodIndex, RangeIndex, | ||
|
@@ -992,11 +992,20 @@ def raise_assert_detail(obj, message, left, right, diff=None): | |
left = pprint_thing(left) | ||
elif is_categorical_dtype(left): | ||
left = repr(left) | ||
|
||
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 import PY2 and string_types up top 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. 👍575b2e8 |
||
if PY2 and isinstance(left, string_types): | ||
# left needs to be printable in native text type in python2 | ||
left = left.encode('utf-8') | ||
|
||
if isinstance(right, np.ndarray): | ||
right = pprint_thing(right) | ||
elif is_categorical_dtype(right): | ||
right = repr(right) | ||
|
||
if PY2 and isinstance(right, string_types): | ||
# right needs to be printable in native text type in python2 | ||
right = right.encode('utf-8') | ||
|
||
msg = """{obj} are different | ||
|
||
{message} | ||
|
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.
can you add a test where left is unicode and right is non-unicode (but string)
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.
👍 1f7e231