janisdd / vscode-edit-csv

vs code extension to edit csv files with an excel like table ui
MIT License
212 stars 30 forks source link

csv edit saveBug #102

Closed xiezhipeng-git closed 1 year ago

xiezhipeng-git commented 1 year ago

What OS?

Description

A clear and concise description of what the bug is. when edit csv file,then saved.it will change the end char.delete the Newline character in windows. and then pd.concat to_csv mode="a".it is not has Newline character at the end.like down

csvData: A,B C,D no edit csv and concat mode= "a" get A,B C,D E,F if edit csv and concat mode = "a" get A,B, C,D,E,F It is wrong

Expected behavior

What you'd expect to happen. save as like DataFrame data and auto add \n in the end

csvData: A,B C,D edit csv and concat mode= "a" get A,B C,D E,F

Steps to reproduce

A step by step guide how to reproduce this issue/bug. pd.DataFrame(data=[newData],columns = keys)
A,B will_concat.append(newDataPd) pdConcat = pd.concat(will_concat,ignore_index=True) pdConcat.to_csv(fileName,encoding="utf-8",mode="a",header=hasKey,index=0) A,B C,D edit csv and save in Edit csv windows pd.read_csv(fileName, comment='#', encoding="utf-8") newDataPd = pd.DataFrame(data=[newData],columns = keys) will_concat.append(newDataPd) pdConcat = pd.concat(will_concat,ignore_index=True) pdConcat.to_csv(fileName,encoding="utf-8",mode="a",header=hasKey,index=0) now get A,B C,D,E,F It is Wrong

janisdd commented 1 year ago

Removing the last newline apparently makes things easier, see https://github.com/mholt/PapaParse/issues/150 which cites the csv standard https://www.rfc-editor.org/rfc/rfc4180 The last record in the file may or may not have an ending line break

An empty line could mean there are fields missing...

You can get the desired behavior when changing the vs code setting files.insertFinalNewline to true

janisdd commented 1 year ago

I thinks this can be closed