@@ -842,11 +842,11 @@ def test_to_csv_unicodewriter_quoting(self):
842
842
encoding = 'utf-8' )
843
843
844
844
result = buf .getvalue ()
845
- expected = ( '"A","B"' + os . linesep +
846
- '1,"foo"' + os . linesep +
847
- '2,"bar"' + os . linesep +
848
- '3,"baz"' + os . linesep )
849
-
845
+ expected_rows = [ '"A","B"' ,
846
+ '1,"foo"' ,
847
+ '2,"bar"' ,
848
+ '3,"baz"' ]
849
+ expected = tm . convert_rows_list_to_csv_str ( expected_rows )
850
850
assert result == expected
851
851
852
852
def test_to_csv_quote_none (self ):
@@ -857,9 +857,10 @@ def test_to_csv_quote_none(self):
857
857
df .to_csv (buf , quoting = csv .QUOTE_NONE ,
858
858
encoding = encoding , index = False )
859
859
result = buf .getvalue ()
860
- expected = ('A' + os .linesep +
861
- 'hello' + os .linesep +
862
- '{"hello"}' + os .linesep )
860
+ expected_rows = ['A' ,
861
+ 'hello' ,
862
+ '{"hello"}' ]
863
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
863
864
assert result == expected
864
865
865
866
def test_to_csv_index_no_leading_comma (self ):
@@ -868,10 +869,11 @@ def test_to_csv_index_no_leading_comma(self):
868
869
869
870
buf = StringIO ()
870
871
df .to_csv (buf , index_label = False )
871
- expected = ('A,B' + os .linesep +
872
- 'one,1,4' + os .linesep +
873
- 'two,2,5' + os .linesep +
874
- 'three,3,6' + os .linesep )
872
+ expected_rows = ['A,B' ,
873
+ 'one,1,4' ,
874
+ 'two,2,5' ,
875
+ 'three,3,6' ]
876
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
875
877
assert buf .getvalue () == expected
876
878
877
879
def test_to_csv_line_terminators (self ):
@@ -1074,9 +1076,10 @@ def test_to_csv_quoting(self):
1074
1076
'c_string' : ['a' , 'b,c' ],
1075
1077
})
1076
1078
1077
- expected = (',c_bool,c_float,c_int,c_string' + os .linesep +
1078
- '0,True,1.0,42.0,a' + os .linesep +
1079
- '1,False,3.2,,"b,c"' + os .linesep )
1079
+ expected_rows = [',c_bool,c_float,c_int,c_string' ,
1080
+ '0,True,1.0,42.0,a' ,
1081
+ '1,False,3.2,,"b,c"' ]
1082
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1080
1083
result = df .to_csv ()
1081
1084
assert result == expected
1082
1085
@@ -1086,19 +1089,19 @@ def test_to_csv_quoting(self):
1086
1089
result = df .to_csv (quoting = csv .QUOTE_MINIMAL )
1087
1090
assert result == expected
1088
1091
1089
- expected = ( '"","c_bool","c_float","c_int","c_string"' + os . linesep +
1090
- '"0","True","1.0","42.0","a"' + os . linesep +
1091
- '"1","False","3.2","","b,c"' + os . linesep )
1092
-
1092
+ expected_rows = [ '"","c_bool","c_float","c_int","c_string"' ,
1093
+ '"0","True","1.0","42.0","a"' ,
1094
+ '"1","False","3.2","","b,c"' ]
1095
+ expected = tm . convert_rows_list_to_csv_str ( expected_rows )
1093
1096
result = df .to_csv (quoting = csv .QUOTE_ALL )
1094
1097
assert result == expected
1095
1098
1096
1099
# see gh-12922, gh-13259: make sure changes to
1097
1100
# the formatters do not break this behaviour
1098
- expected = ( '"","c_bool","c_float","c_int","c_string"' + os . linesep +
1099
- '0,True,1.0,42.0,"a"' + os . linesep +
1100
- '1,False,3.2,"","b,c"' + os . linesep )
1101
-
1101
+ expected_rows = [ '"","c_bool","c_float","c_int","c_string"' ,
1102
+ '0,True,1.0,42.0,"a"' ,
1103
+ '1,False,3.2,"","b,c"' ]
1104
+ expected = tm . convert_rows_list_to_csv_str ( expected_rows )
1102
1105
result = df .to_csv (quoting = csv .QUOTE_NONNUMERIC )
1103
1106
assert result == expected
1104
1107
@@ -1109,24 +1112,27 @@ def test_to_csv_quoting(self):
1109
1112
quoting = csv .QUOTE_NONE ,
1110
1113
escapechar = None )
1111
1114
1112
- expected = (',c_bool,c_float,c_int,c_string' + os .linesep +
1113
- '0,True,1.0,42.0,a' + os .linesep +
1114
- '1,False,3.2,,b!,c' + os .linesep )
1115
+ expected_rows = [',c_bool,c_float,c_int,c_string' ,
1116
+ '0,True,1.0,42.0,a' ,
1117
+ '1,False,3.2,,b!,c' ]
1118
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1115
1119
result = df .to_csv (quoting = csv .QUOTE_NONE ,
1116
1120
escapechar = '!' )
1117
1121
assert result == expected
1118
1122
1119
- expected = (',c_bool,c_ffloat,c_int,c_string' + os .linesep +
1120
- '0,True,1.0,42.0,a' + os .linesep +
1121
- '1,False,3.2,,bf,c' + os .linesep )
1123
+ expected_rows = [',c_bool,c_ffloat,c_int,c_string' ,
1124
+ '0,True,1.0,42.0,a' ,
1125
+ '1,False,3.2,,bf,c' ]
1126
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1122
1127
result = df .to_csv (quoting = csv .QUOTE_NONE ,
1123
1128
escapechar = 'f' )
1124
1129
assert result == expected
1125
1130
1126
1131
# see gh-3503: quoting Windows line terminators
1127
1132
# presents with encoding?
1128
- text = ('a,b,c' + os .linesep +
1129
- '1,"test \r \n ",3' + os .linesep )
1133
+ text_rows = ['a,b,c' ,
1134
+ '1,"test \r \n ",3' ]
1135
+ text = tm .convert_rows_list_to_csv_str (text_rows )
1130
1136
df = pd .read_csv (StringIO (text ))
1131
1137
buf = StringIO ()
1132
1138
df .to_csv (buf , encoding = 'utf-8' , index = False )
@@ -1136,9 +1142,10 @@ def test_to_csv_quoting(self):
1136
1142
# with multi-indexes
1137
1143
df = pd .DataFrame ({'a' : [1 , 2 ], 'b' : [3 , 4 ], 'c' : [5 , 6 ]})
1138
1144
df = df .set_index (['a' , 'b' ])
1139
- expected = ('"a","b","c"' + os .linesep +
1140
- '"1","3","5"' + os .linesep +
1141
- '"2","4","6"' + os .linesep )
1145
+ expected_rows = ['"a","b","c"' ,
1146
+ '"1","3","5"' ,
1147
+ '"2","4","6"' ]
1148
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1142
1149
assert df .to_csv (quoting = csv .QUOTE_ALL ) == expected
1143
1150
1144
1151
def test_period_index_date_overflow (self ):
@@ -1150,19 +1157,21 @@ def test_period_index_date_overflow(self):
1150
1157
df = pd .DataFrame ([4 , 5 , 6 ], index = index )
1151
1158
result = df .to_csv ()
1152
1159
1153
- expected = (',0' + os .linesep +
1154
- '1990-01-01,4' + os .linesep +
1155
- '2000-01-01,5' + os .linesep +
1156
- '3005-01-01,6' + os .linesep )
1160
+ expected_rows = [',0' ,
1161
+ '1990-01-01,4' ,
1162
+ '2000-01-01,5' ,
1163
+ '3005-01-01,6' ]
1164
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1157
1165
assert result == expected
1158
1166
1159
1167
date_format = "%m-%d-%Y"
1160
1168
result = df .to_csv (date_format = date_format )
1161
1169
1162
- expected = (',0' + os .linesep +
1163
- '01-01-1990,4' + os .linesep +
1164
- '01-01-2000,5' + os .linesep +
1165
- '01-01-3005,6' + os .linesep )
1170
+ expected_rows = [',0' ,
1171
+ '01-01-1990,4' ,
1172
+ '01-01-2000,5' ,
1173
+ '01-01-3005,6' ]
1174
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1166
1175
assert result == expected
1167
1176
1168
1177
# Overflow with pd.NaT
@@ -1172,10 +1181,11 @@ def test_period_index_date_overflow(self):
1172
1181
df = pd .DataFrame ([4 , 5 , 6 ], index = index )
1173
1182
result = df .to_csv ()
1174
1183
1175
- expected = (',0' + os .linesep +
1176
- '1990-01-01,4' + os .linesep +
1177
- ',5' + os .linesep +
1178
- '3005-01-01,6' + os .linesep )
1184
+ expected_rows = [',0' ,
1185
+ '1990-01-01,4' ,
1186
+ ',5' ,
1187
+ '3005-01-01,6' ]
1188
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1179
1189
assert result == expected
1180
1190
1181
1191
def test_multi_index_header (self ):
@@ -1188,7 +1198,8 @@ def test_multi_index_header(self):
1188
1198
header = ["a" , "b" , "c" , "d" ]
1189
1199
result = df .to_csv (header = header )
1190
1200
1191
- expected = (',a,b,c,d' + os .linesep +
1192
- '0,1,2,3,4' + os .linesep +
1193
- '1,5,6,7,8' + os .linesep )
1201
+ expected_rows = [',a,b,c,d' ,
1202
+ '0,1,2,3,4' ,
1203
+ '1,5,6,7,8' ]
1204
+ expected = tm .convert_rows_list_to_csv_str (expected_rows )
1194
1205
assert result == expected
0 commit comments