Skip to content

to_clipboard() locks clipboard system-wide on exception #8304

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

Closed
klonuo opened this issue Sep 17, 2014 · 2 comments
Closed

to_clipboard() locks clipboard system-wide on exception #8304

klonuo opened this issue Sep 17, 2014 · 2 comments
Labels
Error Reporting Incorrect or improved errors from pandas

Comments

@klonuo
Copy link
Contributor

klonuo commented Sep 17, 2014

Exception in the following code locks clipboard system-wide until I exit my interactive Python session:

import pandas as pd
df = pd.DataFrame.from_dict({1: u' \u2014'}, 'index')
df.to_clipboard()
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
<ipython-input-58-1f8b11f0ff98> in <module>()
----> 1 df.to_clipboard()

C:\Python27\lib\site-packages\pandas\core\generic.pyc in to_clipboard(self, excel, sep, **kwargs)
   1000         from pandas.io import clipboard
-> 1001         clipboard.to_clipboard(self, excel=excel, sep=sep, **kwargs)
   1002 
   1003     #----------------------------------------------------------------------

C:\Python27\lib\site-packages\pandas\io\clipboard.pyc in to_clipboard(obj, excel, sep, **kwargs)
     95     else:
     96         objstr = str(obj)
---> 97     clipboard_set(objstr)

C:\Python27\lib\site-packages\pandas\util\clipboard.pyc in winSetClipboard(text)
     63     try:
     64         # works on Python 2 (bytes() only takes one argument)
---> 65         hCd = ctypes.windll.kernel32.GlobalAlloc(GMEM_DDESHARE, len(bytes(text))+1)
     66     except TypeError:
     67         # works on Python 3 (bytes() requires an encoding)

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2014' in position 10: ordinal not in range(128)

pandas 0.14.1

@jreback
Copy link
Contributor

jreback commented Sep 18, 2014

where its failing is copied from pyperclip. (though its included in pandas under license). So it is possible to modify.

I suppose you can just do those windows locks in a with. Though I am not really familiar with how windows works in that regard.

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Sep 18, 2014
@jreback
Copy link
Contributor

jreback commented Oct 20, 2015

closing as stale. pls reopen if still an issue.

@jreback jreback closed this as completed Oct 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

2 participants