Skip to content

Commit b9d8b26

Browse files
Licht-Tgfyoung
authored andcommitted
TST: Add to_csv test when writing the single column CSV (pandas-dev#19091)
Closes pandas-devgh-18676
1 parent 324379c commit b9d8b26

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pandas/tests/io/formats/test_to_csv.py

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import sys
34
import numpy as np
45
import pandas as pd
56
import pytest
@@ -9,6 +10,37 @@
910

1011
class TestToCSV(object):
1112

13+
@pytest.mark.xfail((3, 6, 5) > sys.version_info >= (3, 5),
14+
reason=("Python csv library bug "
15+
"(see https://bugs.python.org/issue32255)"))
16+
def test_to_csv_with_single_column(self):
17+
# see gh-18676, https://bugs.python.org/issue32255
18+
#
19+
# Python's CSV library adds an extraneous '""'
20+
# before the newline when the NaN-value is in
21+
# the first row. Otherwise, only the newline
22+
# character is added. This behavior is inconsistent
23+
# and was patched in https://bugs.python.org/pull_request4672.
24+
df1 = DataFrame([None, 1])
25+
expected1 = """\
26+
""
27+
1.0
28+
"""
29+
with tm.ensure_clean('test.csv') as path:
30+
df1.to_csv(path, header=None, index=None)
31+
with open(path, 'r') as f:
32+
assert f.read() == expected1
33+
34+
df2 = DataFrame([1, None])
35+
expected2 = """\
36+
1.0
37+
""
38+
"""
39+
with tm.ensure_clean('test.csv') as path:
40+
df2.to_csv(path, header=None, index=None)
41+
with open(path, 'r') as f:
42+
assert f.read() == expected2
43+
1244
def test_to_csv_defualt_encoding(self):
1345
# GH17097
1446
df = DataFrame({'col': [u"AAAAA", u"ÄÄÄÄÄ", u"ßßßßß", u"聞聞聞聞聞"]})

0 commit comments

Comments
 (0)