Skip to content

to_clipboard wrong linebreaks on Windows #11720

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

Open
Winand opened this issue Nov 30, 2015 · 15 comments
Open

to_clipboard wrong linebreaks on Windows #11720

Winand opened this issue Nov 30, 2015 · 15 comments
Labels
Bug Windows Windows OS

Comments

@Winand
Copy link
Contributor

Winand commented Nov 30, 2015

Copying dataframe with to_clipboard and Qt gives different results: when pasted to Excel there's one more empty line. It may be unexpected and overwrite important data.

When looking into clipboard with Free Clipboard Viewer we can see that Qt uses CR+LF linebreaks:
image
and pandas uses LF:
image
Maybe this is the source of problem.

(This isn't fixed by #9693)

@Winand Winand changed the title to_clipboard line breaks on Windows to_clipboard wrong linebreaks on Windows Nov 30, 2015
@jreback
Copy link
Contributor

jreback commented Nov 30, 2015

you might need to specifier the separator, this is using read_csv under the hood. Pls investigate what would make this work.

@jreback jreback added Windows Windows OS Compat pandas objects compatability with Numpy or Python functions labels Nov 30, 2015
@Winand
Copy link
Contributor Author

Winand commented Nov 30, 2015

This helps:

pd.DataFrame(["Hello world"]).to_clipboard(line_terminator="\r\n")

P.S. you mean to_csv? i think \r\n should be default terminator, cause it concerns Excel=True argument

@jreback
Copy link
Contributor

jreback commented Dec 1, 2015

sorry, meant to_csv. excel=True already implies sep='\t', so not sure what you think should change here.

@Winand
Copy link
Contributor Author

Winand commented Dec 1, 2015

What? I do not understand.) It also implies line_terminator to be '\r\n', cause we're going to paste data in Excel. But it is '\n' by default.

@jreback
Copy link
Contributor

jreback commented Dec 1, 2015

@Winand sorry, was distracted a bit.....yes it is whatever the default line_terminator is in to_csv, which is \n. This works with excel now, so are you suggesting this should default (on windows) to \n\r?

@Winand
Copy link
Contributor Author

Winand commented Dec 1, 2015

@jreback i mean:
if we say Excel=True, we assume that data in clipboard may be pasted into Excel. BUT. If line terminators are '\n' (by default) an unwanted empty line is pasted. So i suggest to set line_terminator to '\r\n' by default on Windows.

@jreback
Copy link
Contributor

jreback commented Dec 1, 2015

but this DOES work on windows. can you give a copy-pastable example where this does not work?

I am not sure how QT interacts with things in any event.

@Winand
Copy link
Contributor Author

Winand commented Dec 1, 2015

Right now i have pandas 0.16.2 patched with #9693 (works the same as 0.17.0 with #9693)

import pandas as pd
pd.DataFrame(["Привет, мир"]).to_clipboard()

Ctrl+V in Excel:
image
Empty line pasted, u see? And now with \r\n:

pd.DataFrame(["Привет, мир"]).to_clipboard(line_terminator='\r\n')

Ctrl+V in Excel:
image

@jreback
Copy link
Contributor

jreback commented Dec 1, 2015

I see that. Hmm, must have always been like that.

@sinhrks @TomAugspurger ever seen this? does it matter?

@TomAugspurger
Copy link
Contributor

Haven't tried to_clipboard -> excel before, but just tested it on windows and I see the extra line.

Not sure what if anything this could break if we change the default. Presumably people on Windows would expect the default to be \r\n?

@sinhrks
Copy link
Member

sinhrks commented Dec 7, 2015

Confirmed the issue on my Windows also. And changing line sep sounds valid. I think we can use os.linesep (\r\n on windows) as default?

@jreback jreback added this to the 0.18.0 milestone Dec 7, 2015
@jreback
Copy link
Contributor

jreback commented Dec 7, 2015

this is actually tricky because say you do to_clipboard, we don't know which platform its going to be pasted, though I suppose we can assume that its the SAME as the current platform.

Though I suppose non-windows platforms can handle the os.linesep correctly. can someone test this out?

e.g.

do these produce differing results on non-windows? (these work for me on macosx)

for term in ['\n','\r\n']:
    df.to_clipboard(line_terminator=term)

so is soln just to default line_terminator='\r\n'?

@jreback
Copy link
Contributor

jreback commented Jan 24, 2016

anyone want to do a PR for this?

@Winand
Copy link
Contributor Author

Winand commented Jan 25, 2016

here it is #12131

@jreback
Copy link
Contributor

jreback commented Nov 22, 2016

4a1a330
updated the vendored pyperclip. does this resolve?

@WillAyd WillAyd mentioned this issue Sep 17, 2019
5 tasks
@mroeschke mroeschke added Bug and removed Compat pandas objects compatability with Numpy or Python functions labels Apr 5, 2020
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Windows Windows OS
Projects
None yet
5 participants