-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix #12529 / Improve to_clipboard for objects containing unicode #12580
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
Conversation
move to 0.18.1 |
use the option display.encoding for the actual encoding |
pls add a test |
I'll look into adding a test tomorrow. |
hmm ok look in the code and see how display.encoding is determined as well it may be that that is wrong (iow not taking into account the locale) or this is just different |
Before writing a new test I ran the tests in "test_clipboard.py" on the unmodified 0.18.0rc1 installation. Surprisingly they fail:
|
After fixing pandas\util\testing.py, I still get a failure:
|
yeah these currently fail on windows py2 (and I have a single/different one failing on macosx), but nothing fails on linux (which is where Travis runs). They all work on py3. I think we have an issue about that. But if not, can you open one. Something is still not being encoded correctly. Of course if you can figure out would be great! |
can you rebase / update |
@dalito Are you still working on it? If I'm not mistaken the errors you're getting are caused by This solution: pijucha@e53dcb0 works for me in python2 (both windows and linux). You can test it and include in your PR if it also works for you. |
except UnicodeEncodeError: | ||
# try again with encoding from locale | ||
from locale import getdefaultlocale | ||
obj.to_csv(buf, sep=sep, encoding=getdefaultlocale()[1], **kwargs) |
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.
I believe using default locale is not necessary. utf-8
should do the job (plus decoding buf.getvalue
to utf-8
) . The windows code of pyperclip
(pandas.util.clipboard
) would ultimately convert it back to unicode.
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.
It is a while ago since I looked at this. I just remember that I found some edge cases which still failed. I'll try to find my test cases to see if what you propose works.
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.
Thanks. I didn't want to submit a new PR while yours is open. But probably more important is whether this works for your edge cases and on your system.
can you rebase / update? |
Superceded by #14599
git diff upstream/master | flake8 --diff
I added the whatsnew entry to 0.18.0.