|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
| 3 | +import sys |
3 | 4 | import numpy as np
|
4 | 5 | import pandas as pd
|
5 | 6 | import pytest
|
|
9 | 10 |
|
10 | 11 | class TestToCSV(object):
|
11 | 12 |
|
| 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 | + |
12 | 44 | def test_to_csv_defualt_encoding(self):
|
13 | 45 | # GH17097
|
14 | 46 | df = DataFrame({'col': [u"AAAAA", u"ÄÄÄÄÄ", u"ßßßßß", u"聞聞聞聞聞"]})
|
|
0 commit comments