Skip to content
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

Use newline='' for csv.writer #1368

Merged
merged 1 commit into from
May 7, 2022
Merged

Conversation

daviewales
Copy link
Contributor

Fixes #1362

According to the docs for csv.writer:

If csvfile is a file object, it should be opened with newline=''
https://docs.python.org/3/library/csv.html#csv.writer

Additionally:

If newline='' is not specified, newlines embedded inside quoted fields will
not be interpreted correctly, and on platforms that use \r\n linendings on
write an extra \r will be added. It should always be safe to specify
newline='', since the csv module does its own (universal) newline handling.
https://docs.python.org/3/library/csv.html#id3

This commit adds newline=None as a keyword argument for open_text in
path.py. It then uses this new keyword argument when opening a file
for writing in loaders/csv.py

@CLAassistant
Copy link

CLAassistant commented May 5, 2022

CLA assistant check
All committers have signed the CLA.

@daviewales
Copy link
Contributor Author

daviewales commented May 5, 2022

Hmm... This fixes the CRCRLF issue on Windows, and doesn't break simple CSVs on *nix. But I'm not quite sure why it's breaking the tests.

EDIT: It's because I changed the wrong function... 😮 Fixed now.

Fixes saulpw#1362

According to the docs for csv.writer:

> If csvfile is a file object, it should be opened with newline=''
> https://docs.python.org/3/library/csv.html#csv.writer

Additionally:

> If newline='' is not specified, newlines embedded inside quoted fields will
> not be interpreted correctly, and on platforms that use \r\n linendings on
> write an extra \r will be added. It should always be safe to specify
> newline='', since the csv module does its own (universal) newline handling.
> https://docs.python.org/3/library/csv.html#id3

This commit adds `newline=None` as a keyword argument for `open_text` in
`path.py`. It then uses this new keyword argument when opening a file
for writing in `loaders/csv.py`
@saulpw saulpw merged commit 7a5e834 into saulpw:develop May 7, 2022
@saulpw
Copy link
Owner

saulpw commented May 7, 2022

Thanks so much for tracking this down and fixing it, @daviewales! Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants