@@ -32,7 +32,7 @@ def test_to_csv_with_single_column(self):
32
32
"""
33
33
with tm .ensure_clean ("test.csv" ) as path :
34
34
df1 .to_csv (path , header = None , index = None )
35
- with open (path ) as f :
35
+ with open (path , encoding = "utf-8" ) as f :
36
36
assert f .read () == expected1
37
37
38
38
df2 = DataFrame ([1 , None ])
@@ -42,7 +42,7 @@ def test_to_csv_with_single_column(self):
42
42
"""
43
43
with tm .ensure_clean ("test.csv" ) as path :
44
44
df2 .to_csv (path , header = None , index = None )
45
- with open (path ) as f :
45
+ with open (path , encoding = "utf-8" ) as f :
46
46
assert f .read () == expected2
47
47
48
48
def test_to_csv_default_encoding (self ):
@@ -64,7 +64,7 @@ def test_to_csv_quotechar(self):
64
64
65
65
with tm .ensure_clean ("test.csv" ) as path :
66
66
df .to_csv (path , quoting = 1 ) # 1=QUOTE_ALL
67
- with open (path ) as f :
67
+ with open (path , encoding = "utf-8" ) as f :
68
68
assert f .read () == expected
69
69
70
70
expected = """\
@@ -75,7 +75,7 @@ def test_to_csv_quotechar(self):
75
75
76
76
with tm .ensure_clean ("test.csv" ) as path :
77
77
df .to_csv (path , quoting = 1 , quotechar = "$" )
78
- with open (path ) as f :
78
+ with open (path , encoding = "utf-8" ) as f :
79
79
assert f .read () == expected
80
80
81
81
with tm .ensure_clean ("test.csv" ) as path :
@@ -92,7 +92,7 @@ def test_to_csv_doublequote(self):
92
92
93
93
with tm .ensure_clean ("test.csv" ) as path :
94
94
df .to_csv (path , quoting = 1 , doublequote = True ) # QUOTE_ALL
95
- with open (path ) as f :
95
+ with open (path , encoding = "utf-8" ) as f :
96
96
assert f .read () == expected
97
97
98
98
with tm .ensure_clean ("test.csv" ) as path :
@@ -109,7 +109,7 @@ def test_to_csv_escapechar(self):
109
109
110
110
with tm .ensure_clean ("test.csv" ) as path : # QUOTE_ALL
111
111
df .to_csv (path , quoting = 1 , doublequote = False , escapechar = "\\ " )
112
- with open (path ) as f :
112
+ with open (path , encoding = "utf-8" ) as f :
113
113
assert f .read () == expected
114
114
115
115
df = DataFrame ({"col" : ["a,a" , ",bb," ]})
@@ -121,7 +121,7 @@ def test_to_csv_escapechar(self):
121
121
122
122
with tm .ensure_clean ("test.csv" ) as path :
123
123
df .to_csv (path , quoting = 3 , escapechar = "\\ " ) # QUOTE_NONE
124
- with open (path ) as f :
124
+ with open (path , encoding = "utf-8" ) as f :
125
125
assert f .read () == expected
126
126
127
127
def test_csv_to_string (self ):
@@ -401,7 +401,7 @@ def test_to_csv_string_array_ascii(self):
401
401
"""
402
402
with tm .ensure_clean ("str_test.csv" ) as path :
403
403
df .to_csv (path , encoding = "ascii" )
404
- with open (path ) as f :
404
+ with open (path , encoding = "utf-8" ) as f :
405
405
assert f .read () == expected_ascii
406
406
407
407
def test_to_csv_string_array_utf8 (self ):
@@ -415,7 +415,7 @@ def test_to_csv_string_array_utf8(self):
415
415
"""
416
416
with tm .ensure_clean ("unicode_test.csv" ) as path :
417
417
df .to_csv (path , encoding = "utf-8" )
418
- with open (path ) as f :
418
+ with open (path , encoding = "utf-8" ) as f :
419
419
assert f .read () == expected_utf8
420
420
421
421
def test_to_csv_string_with_lf (self ):
@@ -521,10 +521,10 @@ def test_to_csv_write_to_open_file(self):
521
521
z
522
522
"""
523
523
with tm .ensure_clean ("test.txt" ) as path :
524
- with open (path , "w" ) as f :
524
+ with open (path , "w" , encoding = "utf-8" ) as f :
525
525
f .write ("manual header\n " )
526
526
df .to_csv (f , header = None , index = None )
527
- with open (path ) as f :
527
+ with open (path , encoding = "utf-8" ) as f :
528
528
assert f .read () == expected
529
529
530
530
def test_to_csv_write_to_open_file_with_newline_py3 (self ):
@@ -534,7 +534,7 @@ def test_to_csv_write_to_open_file_with_newline_py3(self):
534
534
expected_rows = ["x" , "y" , "z" ]
535
535
expected = "manual header\n " + tm .convert_rows_list_to_csv_str (expected_rows )
536
536
with tm .ensure_clean ("test.txt" ) as path :
537
- with open (path , "w" , newline = "" ) as f :
537
+ with open (path , "w" , newline = "" , encoding = "utf-8" ) as f :
538
538
f .write ("manual header\n " )
539
539
df .to_csv (f , header = None , index = None )
540
540
0 commit comments