-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
fix hashing string-casting error #21187
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
Changes from 2 commits
0fab6a9
24a0f59
a879d69
279a6e1
3f8e9b2
35ca0cd
9a37725
7f12013
3b91c00
7ab9324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
import sys | ||
|
||
import pytest | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
@@ -202,6 +203,35 @@ def test_latex_repr(self): | |
|
||
class TestCategoricalRepr(object): | ||
|
||
@pytest.mark.skipif(compat.PY3, reason="Decoding failure only in PY2") | ||
def test_categorical_repr_unicode(self): | ||
# GH#21002 if len(index) > 60, sys.getdefaultencoding()=='ascii', | ||
# and we are working in PY2, then rendering a Categorical could raise | ||
# UnicodeDecodeError by trying to decode when it shouldn't | ||
from pandas.core.base import StringMixin | ||
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 import at the top |
||
|
||
class County(StringMixin): | ||
name = u'San Sebastián' | ||
state = u'PR' | ||
|
||
def __unicode__(self): | ||
return self.name + u', ' + self.state | ||
|
||
cat = pd.Categorical([County() for n in range(61)]) | ||
idx = pd.Index(cat) | ||
ser = idx.to_series() | ||
|
||
# set sys.defaultencoding to ascii, then change it back after the test | ||
enc = sys.getdefaultencoding() | ||
reload(sys) # noqa:F821 | ||
sys.setdefaultencoding('ascii') | ||
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. there is a context manager this i think 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. There is a context manager for 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. yes pls use that 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. Looks like |
||
try: | ||
repr(ser) | ||
str(ser) | ||
finally: | ||
# restore encoding | ||
sys.setdefaultencoding(enc) | ||
|
||
def test_categorical_repr(self): | ||
a = Series(Categorical([1, 2, 3, 4])) | ||
exp = u("0 1\n1 2\n2 3\n3 4\n" + | ||
|
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.
we need a test for py3 as well that uses utf8 as the encoding
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.
Sure, couldn't hurt.