Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame({'numbers': [1, 2, 3], 'colors': ['red', 'white', 'blue']})
df.to_clipboard(index_names=False, header=False)
Gives the following trace.
C:\ProgramData\Miniforge3\lib\site-packages\pandas\io\clipboards.py:133: UserWarning: to_clipboard in excel mode requires a single character separator.
warnings.warn(
Issue Description
The same error occurs regardless of whether I do not specify a separator, or if I include sep="," as an argument. In both cases, I am not specifying a separator of more than 1 character and there should be no problem passing this to to_csv().
Inspecting the source code at https://github.com/pandas-dev/pandas/blob/master/pandas/io/clipboards.py it appears we are correctly being caught by the if excel
statement on line 120 (since we are in excel mode by default) but the try/except wrapper around the call to to_csv() is catching a TypeError. Further inspection is needed to identify what is causing the exception.
Tested in both pandas v1.2.3 and latest version v1.3.4.
I'm using miniconda on Windows 10.
Expected Behavior
The dataframe should be copied to the clipboard as string text without an exception being caught.
Installed Versions
INSTALLED VERSIONS
commit : 945c9ed
python : 3.8.12.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18363
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
pandas : 1.3.4
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3
setuptools : 58.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.2
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fsspec : 2021.10.1
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None