You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above is a well-known problem when mixing unicode and non-unicode strings in python2: The fix (for python 2) is very simple, just add a u in front of the exception_msg string literal in https://github.com/pydata/pandas/blob/master/pandas/tools/pivot.py#L178 i.e line 178 should be exception_msg = u'Conflicting name "{0}" in margins'.format(margins_name)
I am not sure what's the correct way to fix that in python 3 and a python2-3 compatible way so I won't provide a PR for that.
The text was updated successfully, but these errors were encountered:
can check the Index if its inferred_type == 'unicode' if the passed value is also unicode, otherwise could raise an error. So I'll mark this as a better error message.
jreback
changed the title
Exception when adding a unicode margins_name in pivot_table
Exception when adding a unicode margins_name in pivot_table
May 26, 2016
I could reproduce the problem. This is the error I'm seeing:
(pandas)bash-3.2$ python
Python 2.7.13 (default, Jun 2 2017, 06:36:47)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.pivot_table(pd.DataFrame({'foo': [1,2,3]}), index=['foo'], aggfunc=len, margins=True, margins_name=u'Δοκιμή')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pandas/core/reshape/pivot.py", line 126, in pivot_table
margins_name=margins_name, fill_value=fill_value)
File "pandas/core/reshape/pivot.py", line 148, in _add_margins
msg = 'Conflicting name "{name}" in margins'.format(name=margins_name)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
Code Sample, a copy-pastable example if possible
This throws UnicodeDecodeError in python2
pd.pivot_table(pd.DataFrame({'foo': [1,2,3]}), index=['foo'], aggfunc=len, margins=True, margins_name=u'Δοκιμή')
Expected Output
Not throwing exception!
output of
pd.show_versions()
The above is a well-known problem when mixing unicode and non-unicode strings in python2: The fix (for python 2) is very simple, just add a
u
in front of theexception_msg
string literal in https://github.com/pydata/pandas/blob/master/pandas/tools/pivot.py#L178 i.e line 178 should beexception_msg = u'Conflicting name "{0}" in margins'.format(margins_name)
I am not sure what's the correct way to fix that in python 3 and a python2-3 compatible way so I won't provide a PR for that.
The text was updated successfully, but these errors were encountered: