11# -*- coding: utf-8 -*-
22
3- from pandas import DataFrame
43import numpy as np
54import pandas as pd
5+ import pytest
6+ from pandas import DataFrame
67from pandas .util import testing as tm
78
89
@@ -197,7 +198,7 @@ def test_to_csv_date_format(self):
197198 expected_ymd_sec )
198199
199200 def test_to_csv_multi_index (self ):
200- # see gh- 6618
201+ # GH 6618
201202 df = DataFrame ([1 ], columns = pd .MultiIndex .from_arrays ([[1 ], [2 ]]))
202203
203204 exp = ",1\n ,2\n 0,1\n "
@@ -223,3 +224,32 @@ def test_to_csv_multi_index(self):
223224
224225 exp = "foo\n bar\n 1\n "
225226 assert df .to_csv (index = False ) == exp
227+
228+ def test_to_csv_string_array_ascii (self ):
229+ # GH 10813
230+ str_array = [{'names' : ['foo' , 'bar' ]}, {'names' : ['baz' , 'qux' ]}]
231+ df = pd .DataFrame (str_array )
232+ expected_ascii = '''\
233+ ,names
234+ 0,"['foo', 'bar']"
235+ 1,"['baz', 'qux']"
236+ '''
237+ with tm .ensure_clean ('str_test.csv' ) as path :
238+ df .to_csv (path , encoding = 'ascii' )
239+ with open (path , 'r' ) as f :
240+ assert f .read () == expected_ascii
241+
242+ @pytest .mark .xfail
243+ def test_to_csv_string_array_utf8 (self ):
244+ # GH 10813
245+ str_array = [{'names' : ['foo' , 'bar' ]}, {'names' : ['baz' , 'qux' ]}]
246+ df = pd .DataFrame (str_array )
247+ expected_utf8 = '''\
248+ ,names
249+ 0,"[u'foo', u'bar']"
250+ 1,"[u'baz', u'qux']"
251+ '''
252+ with tm .ensure_clean ('unicode_test.csv' ) as path :
253+ df .to_csv (path , encoding = 'utf-8' )
254+ with open (path , 'r' ) as f :
255+ assert f .read () == expected_utf8
0 commit comments