Skip to content

BUG: Fix bug in pd.read_clipboard on windows with PY3 (GH4561); not decoding properly #4571

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

Merged
merged 1 commit into from
Aug 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pandas 0.13
with datetimes (:issue:`4532`)
- Fix arithmetic with series/datetimeindex and ``np.timedelta64`` not working the same (:issue:`4134`)
and buggy timedelta in numpy 1.6 (:issue:`4135`)
- Fix bug in ``pd.read_clipboard`` on windows with PY3 (:issue:`4561`); not decoding properly

pandas 0.12
===========
Expand Down
8 changes: 4 additions & 4 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
def isidentifier(s):
return s.isidentifier()

def str_to_bytes(s, encoding='ascii'):
return s.encode(encoding)
def str_to_bytes(s, encoding=None):
return s.encode(encoding or 'ascii')

def bytes_to_str(b, encoding='utf-8'):
return b.decode(encoding)
def bytes_to_str(b, encoding=None):
return b.decode(encoding or 'utf-8')

# have to explicitly put builtins into the namespace
range = range
Expand Down
8 changes: 8 additions & 0 deletions pandas/io/clipboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" io on the clipboard """
from pandas import compat, get_option
from pandas.compat import StringIO

def read_clipboard(**kwargs): # pragma: no cover
Expand All @@ -15,6 +16,13 @@ def read_clipboard(**kwargs): # pragma: no cover
from pandas.util.clipboard import clipboard_get
from pandas.io.parsers import read_table
text = clipboard_get()

# try to decode (if needed on PY3)
if compat.PY3:
try:
text = compat.bytes_to_str(text,encoding=kwargs.get('encoding') or get_option('display.encoding'))
except:
pass
return read_table(StringIO(text), **kwargs)


Expand Down