10
10
from pandas import DataFrame
11
11
import pandas ._testing as tm
12
12
13
- xfail_pyarrow = pytest .mark .usefixtures ("pyarrow_xfail" )
14
13
15
-
16
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
17
14
@pytest .mark .parametrize ("na_values" , [None , ["NaN" ]])
18
15
def test_comment (all_parsers , na_values ):
19
16
parser = all_parsers
@@ -24,11 +21,15 @@ def test_comment(all_parsers, na_values):
24
21
expected = DataFrame (
25
22
[[1.0 , 2.0 , 4.0 ], [5.0 , np .nan , 10.0 ]], columns = ["A" , "B" , "C" ]
26
23
)
24
+ if parser .engine == "pyarrow" :
25
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
26
+ with pytest .raises (ValueError , match = msg ):
27
+ parser .read_csv (StringIO (data ), comment = "#" , na_values = na_values )
28
+ return
27
29
result = parser .read_csv (StringIO (data ), comment = "#" , na_values = na_values )
28
30
tm .assert_frame_equal (result , expected )
29
31
30
32
31
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
32
33
@pytest .mark .parametrize (
33
34
"read_kwargs" , [{}, {"lineterminator" : "*" }, {"delim_whitespace" : True }]
34
35
)
@@ -43,15 +44,25 @@ def test_line_comment(all_parsers, read_kwargs, request):
43
44
if read_kwargs .get ("delim_whitespace" ):
44
45
data = data .replace ("," , " " )
45
46
elif read_kwargs .get ("lineterminator" ):
46
- if parser .engine != "c" :
47
- mark = pytest .mark .xfail (
48
- reason = "Custom terminator not supported with Python engine"
49
- )
50
- request .applymarker (mark )
51
-
52
47
data = data .replace ("\n " , read_kwargs .get ("lineterminator" ))
53
48
54
49
read_kwargs ["comment" ] = "#"
50
+ if parser .engine == "pyarrow" :
51
+ if "lineterminator" in read_kwargs :
52
+ msg = (
53
+ "The 'lineterminator' option is not supported with the 'pyarrow' engine"
54
+ )
55
+ else :
56
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
57
+ with pytest .raises (ValueError , match = msg ):
58
+ parser .read_csv (StringIO (data ), ** read_kwargs )
59
+ return
60
+ elif parser .engine == "python" and read_kwargs .get ("lineterminator" ):
61
+ msg = r"Custom line terminators not supported in python parser \(yet\)"
62
+ with pytest .raises (ValueError , match = msg ):
63
+ parser .read_csv (StringIO (data ), ** read_kwargs )
64
+ return
65
+
55
66
result = parser .read_csv (StringIO (data ), ** read_kwargs )
56
67
57
68
expected = DataFrame (
@@ -60,7 +71,6 @@ def test_line_comment(all_parsers, read_kwargs, request):
60
71
tm .assert_frame_equal (result , expected )
61
72
62
73
63
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
64
74
def test_comment_skiprows (all_parsers ):
65
75
parser = all_parsers
66
76
data = """# empty
@@ -75,11 +85,16 @@ def test_comment_skiprows(all_parsers):
75
85
expected = DataFrame (
76
86
[[1.0 , 2.0 , 4.0 ], [5.0 , np .nan , 10.0 ]], columns = ["A" , "B" , "C" ]
77
87
)
88
+ if parser .engine == "pyarrow" :
89
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
90
+ with pytest .raises (ValueError , match = msg ):
91
+ parser .read_csv (StringIO (data ), comment = "#" , skiprows = 4 )
92
+ return
93
+
78
94
result = parser .read_csv (StringIO (data ), comment = "#" , skiprows = 4 )
79
95
tm .assert_frame_equal (result , expected )
80
96
81
97
82
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
83
98
def test_comment_header (all_parsers ):
84
99
parser = all_parsers
85
100
data = """# empty
@@ -93,11 +108,15 @@ def test_comment_header(all_parsers):
93
108
expected = DataFrame (
94
109
[[1.0 , 2.0 , 4.0 ], [5.0 , np .nan , 10.0 ]], columns = ["A" , "B" , "C" ]
95
110
)
111
+ if parser .engine == "pyarrow" :
112
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
113
+ with pytest .raises (ValueError , match = msg ):
114
+ parser .read_csv (StringIO (data ), comment = "#" , header = 1 )
115
+ return
96
116
result = parser .read_csv (StringIO (data ), comment = "#" , header = 1 )
97
117
tm .assert_frame_equal (result , expected )
98
118
99
119
100
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
101
120
def test_comment_skiprows_header (all_parsers ):
102
121
parser = all_parsers
103
122
data = """# empty
@@ -115,15 +134,28 @@ def test_comment_skiprows_header(all_parsers):
115
134
expected = DataFrame (
116
135
[[1.0 , 2.0 , 4.0 ], [5.0 , np .nan , 10.0 ]], columns = ["A" , "B" , "C" ]
117
136
)
137
+ if parser .engine == "pyarrow" :
138
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
139
+ with pytest .raises (ValueError , match = msg ):
140
+ parser .read_csv (StringIO (data ), comment = "#" , skiprows = 4 , header = 1 )
141
+ return
142
+
118
143
result = parser .read_csv (StringIO (data ), comment = "#" , skiprows = 4 , header = 1 )
119
144
tm .assert_frame_equal (result , expected )
120
145
121
146
122
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
123
147
@pytest .mark .parametrize ("comment_char" , ["#" , "~" , "&" , "^" , "*" , "@" ])
124
148
def test_custom_comment_char (all_parsers , comment_char ):
125
149
parser = all_parsers
126
150
data = "a,b,c\n 1,2,3#ignore this!\n 4,5,6#ignorethistoo"
151
+
152
+ if parser .engine == "pyarrow" :
153
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
154
+ with pytest .raises (ValueError , match = msg ):
155
+ parser .read_csv (
156
+ StringIO (data .replace ("#" , comment_char )), comment = comment_char
157
+ )
158
+ return
127
159
result = parser .read_csv (
128
160
StringIO (data .replace ("#" , comment_char )), comment = comment_char
129
161
)
@@ -132,7 +164,6 @@ def test_custom_comment_char(all_parsers, comment_char):
132
164
tm .assert_frame_equal (result , expected )
133
165
134
166
135
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
136
167
@pytest .mark .parametrize ("header" , ["infer" , None ])
137
168
def test_comment_first_line (all_parsers , header ):
138
169
# see gh-4623
@@ -144,11 +175,15 @@ def test_comment_first_line(all_parsers, header):
144
175
else :
145
176
expected = DataFrame ([[1 , 2 , 3 ]], columns = ["a" , "b" , "c" ])
146
177
178
+ if parser .engine == "pyarrow" :
179
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
180
+ with pytest .raises (ValueError , match = msg ):
181
+ parser .read_csv (StringIO (data ), comment = "#" , header = header )
182
+ return
147
183
result = parser .read_csv (StringIO (data ), comment = "#" , header = header )
148
184
tm .assert_frame_equal (result , expected )
149
185
150
186
151
- @xfail_pyarrow # ValueError: The 'comment' option is not supported
152
187
def test_comment_char_in_default_value (all_parsers , request ):
153
188
# GH#34002
154
189
if all_parsers .engine == "c" :
@@ -164,6 +199,11 @@ def test_comment_char_in_default_value(all_parsers, request):
164
199
"4,5#,6,10\n "
165
200
"7,8,#N/A,11\n "
166
201
)
202
+ if parser .engine == "pyarrow" :
203
+ msg = "The 'comment' option is not supported with the 'pyarrow' engine"
204
+ with pytest .raises (ValueError , match = msg ):
205
+ parser .read_csv (StringIO (data ), comment = "#" , na_values = "#N/A" )
206
+ return
167
207
result = parser .read_csv (StringIO (data ), comment = "#" , na_values = "#N/A" )
168
208
expected = DataFrame (
169
209
{
0 commit comments