-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Prevent UnicodeDecodeError in pivot_table under Py2 #17489
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 3 commits
45e99bf
01991e9
e851082
0d593cb
ce96abd
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from pandas.core.groupby import Grouper | ||
from pandas.core.reshape.util import cartesian_product | ||
from pandas.core.index import Index, _get_objs_combined_axis | ||
from pandas.compat import range, lrange, zip | ||
from pandas.compat import range, lrange, zip, u | ||
from pandas import compat | ||
import pandas.core.common as com | ||
from pandas.util._decorators import Appender, Substitution | ||
|
@@ -145,7 +145,7 @@ def _add_margins(table, data, values, rows, cols, aggfunc, | |
if not isinstance(margins_name, compat.string_types): | ||
raise ValueError('margins_name argument must be a string') | ||
|
||
msg = 'Conflicting name "{name}" in margins'.format(name=margins_name) | ||
msg = u('Conflicting name "{name}" in margins').format(name=margins_name) | ||
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. The new parentheses can be removed. |
||
for level in table.index.names: | ||
if margins_name in table.index.get_level_values(level): | ||
raise ValueError(msg) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1625,3 +1625,9 @@ def test_isleapyear_deprecate(self): | |
|
||
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): | ||
assert isleapyear(2004) | ||
|
||
def test_issue_13292(self): | ||
# The below shouldn't raise an exception anymore. | ||
frame = pd.DataFrame({'foo': [1, 2, 3]}) | ||
pd.pivot_table(frame, index=['foo'], aggfunc=len, margins=True, | ||
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. you don't need the comment, instead change the test name to something useful like: 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. still like to compare this here 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. I figured out how to construct the expected object correctly. Please have a look. |
||
margins_name=u'\u0394\u03bf\u03ba\u03b9\u03bc\u03ae') | ||
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. get the and compare to a constructed 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. @jreback Could you please suggest what the constructed def test_pivot_margins_name_unicode(self):
# issue #13292
greek = u'\u0394\u03bf\u03ba\u03b9\u03bc\u03ae'
frame = pd.DataFrame({'foo': [1, 2, 3]})
table = pd.pivot_table(frame, index=['foo'], aggfunc=len, margins=True,
margins_name=greek)
expected = pd.DataFrame({}, columns=['foo'], index=[1, 2, 3, greek])
tm.assert_frame_equal(table, expected) This is failing on the last line with 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. don't pass the 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. Thanks for the suggestion. This is what I have now: expected = pd.DataFrame(columns=['foo'], index=[1, 2, 3, greek]) It's still failing:
What else could be wrong? |
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.
write this from a user perspective
Bug in :func:`pandas.pivot_table` incorrectly raising when passing unicode input for
marginskeyword