From fba714b16151cf6aa170659a1f86d67453bf91c4 Mon Sep 17 00:00:00 2001 From: Licht-T Date: Fri, 5 Jan 2018 14:03:53 +0900 Subject: [PATCH 1/2] TST: Add to_csv test for writing the single column CSV --- pandas/tests/io/formats/test_to_csv.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index e12a7196dce6b..52479d21fe082 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import sys import numpy as np import pandas as pd import pytest @@ -9,6 +10,30 @@ class TestToCSV(object): + @pytest.mark.xfail((3, 6, 5) > sys.version_info >= (3, 5), + reason='Python csv library bug') + def test_to_csv_with_single_column(self): + # GH18676 + df1 = DataFrame([None, 1]) + expected1 = """\ +"" +1.0 +""" + with tm.ensure_clean('test.csv') as path: + df1.to_csv(path, header=None, index=None) + with open(path, 'r') as f: + assert f.read() == expected1 + + df2 = DataFrame([1, None]) + expected2 = """\ +1.0 +"" +""" + with tm.ensure_clean('test.csv') as path: + df2.to_csv(path, header=None, index=None) + with open(path, 'r') as f: + assert f.read() == expected2 + def test_to_csv_defualt_encoding(self): # GH17097 df = DataFrame({'col': [u"AAAAA", u"ÄÄÄÄÄ", u"ßßßßß", u"聞聞聞聞聞"]}) From c8dd8135805a9a64eb574d443b13730841148866 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Sat, 10 Feb 2018 23:38:31 -0500 Subject: [PATCH 2/2] Expand comment on why this xfailed test was added --- pandas/tests/io/formats/test_to_csv.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 52479d21fe082..dfa3751bff57a 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -11,9 +11,16 @@ class TestToCSV(object): @pytest.mark.xfail((3, 6, 5) > sys.version_info >= (3, 5), - reason='Python csv library bug') + reason=("Python csv library bug " + "(see https://bugs.python.org/issue32255)")) def test_to_csv_with_single_column(self): - # GH18676 + # see gh-18676, https://bugs.python.org/issue32255 + # + # Python's CSV library adds an extraneous '""' + # before the newline when the NaN-value is in + # the first row. Otherwise, only the newline + # character is added. This behavior is inconsistent + # and was patched in https://bugs.python.org/pull_request4672. df1 = DataFrame([None, 1]) expected1 = """\ ""