@@ -21,7 +21,22 @@ def engine(request):
21
21
return request .param
22
22
23
23
24
+ @pytest .fixture
25
+ def pyarrow_xfail (request ):
26
+ """
27
+ Fixture that xfails a test if the engine is pyarrow.
28
+ """
29
+ engine = request .getfixturevalue ("engine" )
30
+ if engine == "pyarrow" :
31
+ mark = pytest .mark .xfail (reason = "pyarrow doesn't support this." )
32
+ request .node .add_marker (mark )
33
+
34
+
35
+ xfail_pyarrow = pytest .mark .usefixtures ("pyarrow_xfail" )
36
+
37
+
24
38
class TestToCSV :
39
+ @xfail_pyarrow
25
40
def test_to_csv_with_single_column (self , engine ):
26
41
# see gh-18676, https://bugs.python.org/issue32255
27
42
#
@@ -59,6 +74,7 @@ def test_to_csv_default_encoding(self, engine):
59
74
df .to_csv (path , engine = engine )
60
75
tm .assert_frame_equal (pd .read_csv (path , index_col = 0 ), df )
61
76
77
+ @xfail_pyarrow
62
78
def test_to_csv_quotechar (self , engine ):
63
79
df = DataFrame ({"col" : [1 , 2 ]})
64
80
expected = """\
@@ -131,12 +147,14 @@ def test_to_csv_escapechar(self, engine=engine):
131
147
with open (path , encoding = "utf-8" ) as f :
132
148
assert f .read () == expected
133
149
150
+ @xfail_pyarrow
134
151
def test_csv_to_string (self , engine ):
135
152
df = DataFrame ({"col" : [1 , 2 ]})
136
153
expected_rows = [",col" , "0,1" , "1,2" ]
137
154
expected = tm .convert_rows_list_to_csv_str (expected_rows )
138
155
assert df .to_csv (engine = engine ) == expected
139
156
157
+ @xfail_pyarrow
140
158
def test_to_csv_decimal (self , engine ):
141
159
# see gh-781
142
160
df = DataFrame ({"col1" : [1 ], "col2" : ["a" ], "col3" : [10.1 ]})
@@ -176,7 +194,8 @@ def test_to_csv_decimal(self, engine):
176
194
# same for a multi-index
177
195
assert df .set_index (["a" , "b" ]).to_csv (engine = engine , decimal = "^" ) == expected
178
196
179
- def test_to_csv_float_format (self ):
197
+ @xfail_pyarrow
198
+ def test_to_csv_float_format (self , engine ):
180
199
# testing if float_format is taken into account for the index
181
200
# GH 11553
182
201
df = DataFrame ({"a" : [0 , 1 ], "b" : [2.2 , 3.3 ], "c" : 1 })
@@ -191,7 +210,8 @@ def test_to_csv_float_format(self):
191
210
== expected
192
211
)
193
212
194
- def test_to_csv_na_rep (self ):
213
+ @xfail_pyarrow
214
+ def test_to_csv_na_rep (self , engine ):
195
215
# see gh-11553
196
216
#
197
217
# Testing if NaN values are correctly represented in the index.
@@ -222,6 +242,7 @@ def test_to_csv_na_rep(self):
222
242
expected = tm .convert_rows_list_to_csv_str ([",0" , "0,a" , "1,ZZZZZ" , "2,c" ])
223
243
assert expected == csv
224
244
245
+ @xfail_pyarrow
225
246
def test_to_csv_na_rep_nullable_string (self , nullable_string_dtype , engine ):
226
247
# GH 29975
227
248
# Make sure full na_rep shows up when a dtype is provided
@@ -231,6 +252,7 @@ def test_to_csv_na_rep_nullable_string(self, nullable_string_dtype, engine):
231
252
)
232
253
assert expected == csv
233
254
255
+ @xfail_pyarrow
234
256
def test_to_csv_date_format (self , engine ):
235
257
# GH 10209
236
258
df_sec = DataFrame ({"A" : pd .date_range ("20130101" , periods = 5 , freq = "s" )})
@@ -302,6 +324,7 @@ def test_to_csv_date_format(self, engine):
302
324
== expected_ymd_sec
303
325
)
304
326
327
+ @xfail_pyarrow
305
328
def test_to_csv_different_datetime_formats (self , engine ):
306
329
# GH#21734
307
330
df = DataFrame (
@@ -318,6 +341,7 @@ def test_to_csv_different_datetime_formats(self, engine):
318
341
expected = tm .convert_rows_list_to_csv_str (expected_rows )
319
342
assert df .to_csv (index = False , engine = engine ) == expected
320
343
344
+ @xfail_pyarrow
321
345
def test_to_csv_date_format_in_categorical (self , engine ):
322
346
# GH#40754
323
347
ser = pd .Series (pd .to_datetime (["2021-03-27" , pd .NaT ], format = "%Y-%m-%d" ))
@@ -335,6 +359,7 @@ def test_to_csv_date_format_in_categorical(self, engine):
335
359
ser .to_csv (index = False , engine = engine , date_format = "%Y-%m-%d" ) == expected
336
360
)
337
361
362
+ @xfail_pyarrow
338
363
def test_to_csv_float_ea_float_format (self , engine ):
339
364
# GH#45991
340
365
df = DataFrame ({"a" : [1.1 , 2.02 , pd .NA , 6.000006 ], "b" : "c" })
@@ -345,6 +370,7 @@ def test_to_csv_float_ea_float_format(self, engine):
345
370
)
346
371
assert result == expected
347
372
373
+ @xfail_pyarrow
348
374
def test_to_csv_float_ea_no_float_format (self , engine ):
349
375
# GH#45991
350
376
df = DataFrame ({"a" : [1.1 , 2.02 , pd .NA , 6.000006 ], "b" : "c" })
@@ -355,6 +381,7 @@ def test_to_csv_float_ea_no_float_format(self, engine):
355
381
)
356
382
assert result == expected
357
383
384
+ @xfail_pyarrow
358
385
def test_to_csv_multi_index (self , engine ):
359
386
# see gh-6618
360
387
df = DataFrame ([1 ], columns = pd .MultiIndex .from_arrays ([[1 ], [2 ]]))
@@ -391,6 +418,7 @@ def test_to_csv_multi_index(self, engine):
391
418
exp = tm .convert_rows_list_to_csv_str (exp_rows )
392
419
assert df .to_csv (index = False , engine = engine ) == exp
393
420
421
+ @xfail_pyarrow
394
422
@pytest .mark .parametrize (
395
423
"ind,expected" ,
396
424
[
@@ -415,6 +443,7 @@ def test_to_csv_single_level_multi_index(
415
443
result = obj .to_csv (lineterminator = "\n " , header = True , engine = engine )
416
444
assert result == expected
417
445
446
+ @xfail_pyarrow
418
447
def test_to_csv_string_array_ascii (self , engine ):
419
448
# GH 10813
420
449
str_array = [{"names" : ["foo" , "bar" ]}, {"names" : ["baz" , "qux" ]}]
@@ -429,6 +458,7 @@ def test_to_csv_string_array_ascii(self, engine):
429
458
with open (path , encoding = "utf-8" ) as f :
430
459
assert f .read () == expected_ascii
431
460
461
+ @xfail_pyarrow
432
462
def test_to_csv_string_array_utf8 (self , engine ):
433
463
# GH 10813
434
464
str_array = [{"names" : ["foo" , "bar" ]}, {"names" : ["baz" , "qux" ]}]
@@ -443,6 +473,7 @@ def test_to_csv_string_array_utf8(self, engine):
443
473
with open (path , encoding = "utf-8" ) as f :
444
474
assert f .read () == expected_utf8
445
475
476
+ @xfail_pyarrow
446
477
def test_to_csv_string_with_lf (self , engine ):
447
478
# GH 20353
448
479
data = {"int" : [1 , 2 , 3 ], "str_lf" : ["abc" , "d\n ef" , "g\n h\n \n i" ]}
@@ -477,6 +508,7 @@ def test_to_csv_string_with_lf(self, engine):
477
508
with open (path , "rb" ) as f :
478
509
assert f .read () == expected_crlf
479
510
511
+ @xfail_pyarrow
480
512
def test_to_csv_string_with_crlf (self , engine ):
481
513
# GH 20353
482
514
data = {"int" : [1 , 2 , 3 ], "str_crlf" : ["abc" , "d\r \n ef" , "g\r \n h\r \n \r \n i" ]}
@@ -516,6 +548,7 @@ def test_to_csv_string_with_crlf(self, engine):
516
548
with open (path , "rb" ) as f :
517
549
assert f .read () == expected_crlf
518
550
551
+ @xfail_pyarrow
519
552
def test_to_csv_stdout_file (self , capsys , engine ):
520
553
# GH 21561
521
554
df = DataFrame ([["foo" , "bar" ], ["baz" , "qux" ]], columns = ["name_1" , "name_2" ])
@@ -528,6 +561,7 @@ def test_to_csv_stdout_file(self, capsys, engine):
528
561
assert captured .out == expected_ascii
529
562
assert not sys .stdout .closed
530
563
564
+ @xfail_pyarrow
531
565
@pytest .mark .xfail (
532
566
compat .is_platform_windows (),
533
567
reason = (
@@ -553,6 +587,7 @@ def test_to_csv_write_to_open_file(self, engine):
553
587
with open (path , encoding = "utf-8" ) as f :
554
588
assert f .read () == expected
555
589
590
+ @xfail_pyarrow
556
591
def test_to_csv_write_to_open_file_with_newline_py3 (self , engine ):
557
592
# see gh-21696
558
593
# see gh-20353
@@ -651,6 +686,7 @@ def test_to_csv_zip_infer_name(self, tmp_path, filename, expected_arcname, engin
651
686
archived_file = zp .filelist [0 ].filename
652
687
assert archived_file == expected_arcname
653
688
689
+ @xfail_pyarrow
654
690
@pytest .mark .parametrize ("df_new_type" , ["Int64" ])
655
691
def test_to_csv_na_rep_long_string (self , df_new_type , engine ):
656
692
# see gh-25099
@@ -665,6 +701,7 @@ def test_to_csv_na_rep_long_string(self, df_new_type, engine):
665
701
666
702
assert expected == result
667
703
704
+ @xfail_pyarrow
668
705
def test_to_csv_timedelta_precision (self , engine ):
669
706
# GH 6783
670
707
s = pd .Series ([1 , 1 ]).astype ("timedelta64[ns]" )
@@ -679,6 +716,7 @@ def test_to_csv_timedelta_precision(self, engine):
679
716
expected = tm .convert_rows_list_to_csv_str (expected_rows )
680
717
assert result == expected
681
718
719
+ @xfail_pyarrow
682
720
def test_na_rep_truncated (self , engine ):
683
721
# https://github.com/pandas-dev/pandas/issues/31447
684
722
result = pd .Series (range (8 , 12 )).to_csv (na_rep = "-" , engine = engine )
@@ -693,6 +731,7 @@ def test_na_rep_truncated(self, engine):
693
731
expected = tm .convert_rows_list_to_csv_str ([",0" , "0,1.1" , "1,2.2" ])
694
732
assert result == expected
695
733
734
+ @xfail_pyarrow
696
735
@pytest .mark .parametrize ("errors" , ["surrogatepass" , "ignore" , "replace" ])
697
736
def test_to_csv_errors (self , errors , engine ):
698
737
# GH 22610
@@ -717,6 +756,7 @@ def test_to_csv_binary_handle(self, mode, engine):
717
756
df .to_csv (handle , mode = mode , engine = engine )
718
757
tm .assert_frame_equal (df , pd .read_csv (path , index_col = 0 ))
719
758
759
+ @xfail_pyarrow
720
760
@pytest .mark .parametrize ("mode" , ["wb" , "w" ])
721
761
def test_to_csv_encoding_binary_handle (self , mode , engine ):
722
762
"""
0 commit comments