Skip to content

BUG: to_clipboard fails to format output for Excel #21111

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
742aa3b
Fixed copy table to excel
david-liu-brattle-1 May 17, 2018
a8c098d
Unit Test and whatsnew
david-liu-brattle-1 May 18, 2018
1fee38f
Revert "Unit Test and whatsnew"
david-liu-brattle-1 May 18, 2018
5204489
Merge remote-tracking branch 'upstream/master' into fix-excel-clipboard
david-liu-brattle-1 May 18, 2018
fd1d3dd
Unit test for excel clipboard IO and updated whatsnew
david-liu-brattle-1 May 18, 2018
8439dfe
PEP8
david-liu-brattle-1 May 18, 2018
753e239
Test for function default values
david-liu-brattle-1 May 18, 2018
ba4bc36
More robust clipboard tests
david-liu-brattle-1 May 18, 2018
ef8bf54
Test for correct shape when results aren't expected to exactly match
david-liu-brattle-1 May 18, 2018
4d8a1aa
PEP8
david-liu-brattle-1 May 18, 2018
ce02a40
Formatting
david-liu-brattle-1 May 18, 2018
b46159a
Merge branch 'master' into fix-excel-clipboard
david-liu-brattle-1 Jun 6, 2018
f698ed6
Rebase
david-liu-brattle-1 Jun 6, 2018
2b7b891
Typo
david-liu-brattle-1 Jun 6, 2018
009e3e9
Fixed python 27 compatibility
david-liu-brattle-1 Jun 6, 2018
c4cc756
Merge branch 'master' into fix-excel-clipboard
david-liu-brattle-1 Jun 6, 2018
cd4be4b
Style fix
david-liu-brattle-1 Jun 6, 2018
f7bc16f
Merge branch 'master' of https://github.com/pandas-dev/pandas into fi…
david-liu-brattle-1 Jun 18, 2018
30f5d78
Fix test
david-liu-brattle-1 Jun 18, 2018
e363374
Added warning for excel=False and sep!=None
david-liu-brattle-1 Jun 23, 2018
1a3a6d2
Merge branch 'master' into fix-excel-clipboard
david-liu-brattle-1 Jun 27, 2018
5013d67
Removed xfail, add whatsnew
david-liu-brattle-1 Jun 27, 2018
24a650f
Rebuild
david-liu-brattle-1 Jun 27, 2018
5db662f
Typo fixes
david-liu-brattle-1 Jun 27, 2018
3939bf3
permissions
david-liu-brattle-1 Jun 27, 2018
e50b752
Merge remote-tracking branch 'upstream/master' into david-liu-brattle…
jorisvandenbossche Jun 29, 2018
676a58c
fix warning + small edits
jorisvandenbossche Jun 29, 2018
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.23.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Fixed Regressions
- Bug in both :meth:`DataFrame.first_valid_index` and :meth:`Series.first_valid_index` raised for a row index having duplicate values (:issue:`21441`)
- Fixed regression in unary negative operations with object dtype (:issue:`21380`)
- Bug in :meth:`Timestamp.ceil` and :meth:`Timestamp.floor` when timestamp is a multiple of the rounding frequency (:issue:`21262`)
- Fixed regression in :func:`to_clipboard` that defaulted to copying dataframes with space delimited instead of tab delimited (:issue:`21104`)

.. _whatsnew_0232.performance:

Expand Down Expand Up @@ -115,7 +116,6 @@ Bug Fixes

- Bug in :func:`read_csv` that caused it to incorrectly raise an error when ``nrows=0``, ``low_memory=True``, and ``index_col`` was not ``None`` (:issue:`21141`)
- Bug in :func:`json_normalize` when formatting the ``record_prefix`` with integer columns (:issue:`21536`)
- Bug in :func:`to_clipboard` that defaulted to copying dataframes with space delimited instead of tab delimited (:issue:`21104`)
-

**Plotting**
Expand Down
13 changes: 6 additions & 7 deletions pandas/io/clipboards.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" io on the clipboard """
from pandas import compat, get_option, option_context, DataFrame
from pandas.compat import StringIO
from pandas.compat import StringIO, PY2, PY3
import warnings


Expand Down Expand Up @@ -33,7 +33,7 @@ def read_clipboard(sep=r'\s+', **kwargs): # pragma: no cover

# try to decode (if needed on PY3)
# Strange. linux py33 doesn't complain, win py33 does
if compat.PY3:
if PY3:
try:
text = compat.bytes_to_str(
text, encoding=(kwargs.get('encoding') or
Expand Down Expand Up @@ -67,14 +67,14 @@ def read_clipboard(sep=r'\s+', **kwargs): # pragma: no cover
if len(sep) > 1 and kwargs.get('engine') is None:
kwargs['engine'] = 'python'
elif len(sep) > 1 and kwargs.get('engine') == 'c':
warnings.warn('from_clipboard with regex separator does not work'
warnings.warn('read_clipboard with regex separator does not work'
' properly with c engine')

# In PY2, the c table reader first encodes text with UTF-8 but Python
# table reader uses the format of the passed string. For consistency,
# encode strings for python engine so that output from python and c
# engines produce consistent results
if kwargs.get('engine') == 'python' and compat.PY2:
if kwargs.get('engine') == 'python' and PY2:
text = text.encode('utf-8')

return read_table(StringIO(text), sep=sep, **kwargs)
Expand Down Expand Up @@ -121,14 +121,13 @@ def to_clipboard(obj, excel=True, sep=None, **kwargs): # pragma: no cover
# clipboard_set (pyperclip) expects unicode
obj.to_csv(buf, sep=sep, encoding='utf-8', **kwargs)
text = buf.getvalue()
if compat.PY2:
if PY2:
text = text.decode('utf-8')
clipboard_set(text)
return
except TypeError:
warnings.warn('to_clipboard in excel mode requires a single '
'character separator. Set "excel=False" or change '
'the separator')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@david-liu-brattle-1 I removed the last sentence of this warning, as setting excel=False does not help as then you get the warning that the separator is ignored. It's simply that to_clipboard does not support multiple character separator at all.

'character separator.')
elif sep is not None:
warnings.warn('to_clipboard with excel=False ignores the sep argument')

Expand Down