1
1
# -*- coding: utf-8 -*-
2
2
3
- from pandas import DataFrame
4
3
import numpy as np
5
4
import pandas as pd
5
+ import pytest
6
+ from pandas import DataFrame
6
7
from pandas .util import testing as tm
7
8
8
9
@@ -197,7 +198,7 @@ def test_to_csv_date_format(self):
197
198
expected_ymd_sec )
198
199
199
200
def test_to_csv_multi_index (self ):
200
- # see gh- 6618
201
+ # GH 6618
201
202
df = DataFrame ([1 ], columns = pd .MultiIndex .from_arrays ([[1 ], [2 ]]))
202
203
203
204
exp = ",1\n ,2\n 0,1\n "
@@ -223,3 +224,32 @@ def test_to_csv_multi_index(self):
223
224
224
225
exp = "foo\n bar\n 1\n "
225
226
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