Skip to content

Commit b5ee28b

Browse files
committed
Merge pull request #4571 from jreback/clip
BUG: Fix bug in pd.read_clipboard on windows with PY3 (GH4561); not decoding properly
2 parents b5ff81d + e86bb1a commit b5ee28b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ pandas 0.13
183183
with datetimes (:issue:`4532`)
184184
- Fix arithmetic with series/datetimeindex and ``np.timedelta64`` not working the same (:issue:`4134`)
185185
and buggy timedelta in numpy 1.6 (:issue:`4135`)
186+
- Fix bug in ``pd.read_clipboard`` on windows with PY3 (:issue:`4561`); not decoding properly
186187

187188
pandas 0.12
188189
===========

pandas/compat/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
def isidentifier(s):
5656
return s.isidentifier()
5757

58-
def str_to_bytes(s, encoding='ascii'):
59-
return s.encode(encoding)
58+
def str_to_bytes(s, encoding=None):
59+
return s.encode(encoding or 'ascii')
6060

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

6464
# have to explicitly put builtins into the namespace
6565
range = range

pandas/io/clipboard.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" io on the clipboard """
2+
from pandas import compat, get_option
23
from pandas.compat import StringIO
34

45
def read_clipboard(**kwargs): # pragma: no cover
@@ -15,6 +16,13 @@ def read_clipboard(**kwargs): # pragma: no cover
1516
from pandas.util.clipboard import clipboard_get
1617
from pandas.io.parsers import read_table
1718
text = clipboard_get()
19+
20+
# try to decode (if needed on PY3)
21+
if compat.PY3:
22+
try:
23+
text = compat.bytes_to_str(text,encoding=kwargs.get('encoding') or get_option('display.encoding'))
24+
except:
25+
pass
1826
return read_table(StringIO(text), **kwargs)
1927

2028

0 commit comments

Comments
 (0)