Skip to content

Commit

Permalink
CLN: applied gfyoung's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
deflatSOCO committed Jun 10, 2018
1 parent 415e733 commit 050e8b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ MultiIndex
I/O
^^^

- (Only for Windows) Bug in :meth:`DataFrame.to_csv`, in which all `\n`s are converted to `\r\n` (:issue:`20353`)
- Bug in :meth:`DataFrame.to_csv`, in which all `\n`s are converted to `\r\n` on Windows (:issue:`20353`)
-
-

Expand Down
36 changes: 20 additions & 16 deletions pandas/tests/io/formats/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,24 @@ def test_to_csv_string_with_lf(self):
df = pd.DataFrame(data)

with tm.ensure_clean('lf_test.csv') as path:
expected_bin = \
b'int,str_lf\n' \
b'1,abc\n' \
b'2,"d\nef"\n' \
expected_bin = (
b'int,str_lf\n'
b'1,abc\n'
b'2,"d\nef"\n'
b'3,"g\nh\n\ni"\n'
)

df.to_csv(path, index=False)
with open(path, 'rb') as f:
assert f.read() == expected_bin

# 'line_terminator' should not change inner element
expected_bin = \
b'int,str_lf\r\n' \
b'1,abc\r\n' \
b'2,"d\nef"\r\n' \
expected_bin =(
b'int,str_lf\r\n'
b'1,abc\r\n'
b'2,"d\nef"\r\n'
b'3,"g\nh\n\ni"\r\n'
)

df.to_csv(path, line_terminator='\r\n', index=False)
with open(path, 'rb') as f:
Expand All @@ -325,21 +327,23 @@ def test_to_csv_string_with_crlf(self):
df = pd.DataFrame(data)

with tm.ensure_clean('crlf_test.csv') as path:
expected_bin = \
b'int,str_crlf\n' \
b'1,abc\n' \
b'2,"d\r\nef"\n' \
expected_bin = (
b'int,str_crlf\n'
b'1,abc\n'
b'2,"d\r\nef"\n'
b'3,"g\r\nh\r\n\r\ni"\n'
)

df.to_csv(path, index=False)
with open(path, 'rb') as f:
assert f.read() == expected_bin

expected_bin = \
b'int,str_crlf\r\n' \
b'1,abc\r\n' \
b'2,"d\r\nef"\r\n' \
expected_bin = (
b'int,str_crlf\r\n'
b'1,abc\r\n'
b'2,"d\r\nef"\r\n'
b'3,"g\r\nh\r\n\r\ni"\r\n'
)

df.to_csv(path, line_terminator='\r\n', index=False)
with open(path, 'rb') as f:
Expand Down

0 comments on commit 050e8b5

Please sign in to comment.