Skip to content

Commit fd6fd13

Browse files
committed
TST: Add to_csv test for writing the single column CSV
1 parent be66ef8 commit fd6fd13

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pandas/tests/io/formats/test_to_csv.py

+25
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,30 @@
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+
def test_to_csv_with_single_column(self):
16+
# GH18676
17+
df1 = DataFrame([None, 1])
18+
expected1 = """\
19+
""
20+
1.0
21+
"""
22+
with tm.ensure_clean('test.csv') as path:
23+
df1.to_csv(path, header=None, index=None)
24+
with open(path, 'r') as f:
25+
assert f.read() == expected1
26+
27+
df2 = DataFrame([1, None])
28+
expected2 = """\
29+
1.0
30+
""
31+
"""
32+
with tm.ensure_clean('test.csv') as path:
33+
df2.to_csv(path, header=None, index=None)
34+
with open(path, 'r') as f:
35+
assert f.read() == expected2
36+
1237
def test_to_csv_defualt_encoding(self):
1338
# GH17097
1439
df = DataFrame({'col': [u"AAAAA", u"ÄÄÄÄÄ", u"ßßßßß", u"聞聞聞聞聞"]})

0 commit comments

Comments
 (0)