12
12
import numpy as np
13
13
import pytest
14
14
15
- from pandas ._config import using_string_dtype
16
-
17
- from pandas .compat import HAS_PYARROW
18
15
from pandas .errors import SpecificationError
19
16
20
17
from pandas import (
@@ -212,10 +209,6 @@ def transform(row):
212
209
data .apply (transform , axis = 1 )
213
210
214
211
215
- # we should raise a proper TypeError instead of propagating the pyarrow error
216
- @pytest .mark .xfail (
217
- using_string_dtype () and not HAS_PYARROW , reason = "TODO(infer_string)"
218
- )
219
212
@pytest .mark .parametrize (
220
213
"df, func, expected" ,
221
214
tm .get_cython_table_params (
@@ -225,21 +218,25 @@ def transform(row):
225
218
def test_agg_cython_table_raises_frame (df , func , expected , axis , using_infer_string ):
226
219
# GH 21224
227
220
if using_infer_string :
228
- import pyarrow as pa
221
+ if df .dtypes .iloc [0 ].storage == "pyarrow" :
222
+ import pyarrow as pa
229
223
230
- expected = (expected , pa .lib .ArrowNotImplementedError )
224
+ # TODO(infer_string)
225
+ # should raise a proper TypeError instead of propagating the pyarrow error
231
226
232
- msg = "can't multiply sequence by non-int of type 'str'|has no kernel"
227
+ expected = (expected , pa .lib .ArrowNotImplementedError )
228
+ else :
229
+ expected = (expected , NotImplementedError )
230
+
231
+ msg = (
232
+ "can't multiply sequence by non-int of type 'str'|has no kernel|cannot perform"
233
+ )
233
234
warn = None if isinstance (func , str ) else FutureWarning
234
235
with pytest .raises (expected , match = msg ):
235
236
with tm .assert_produces_warning (warn , match = "using DataFrame.cumprod" ):
236
237
df .agg (func , axis = axis )
237
238
238
239
239
- # we should raise a proper TypeError instead of propagating the pyarrow error
240
- @pytest .mark .xfail (
241
- using_string_dtype () and not HAS_PYARROW , reason = "TODO(infer_string)"
242
- )
243
240
@pytest .mark .parametrize (
244
241
"series, func, expected" ,
245
242
chain (
@@ -263,11 +260,15 @@ def test_agg_cython_table_raises_series(series, func, expected, using_infer_stri
263
260
msg = r"Cannot convert \['a' 'b' 'c'\] to numeric"
264
261
265
262
if using_infer_string :
266
- import pyarrow as pa
267
-
268
- expected = (expected , pa .lib .ArrowNotImplementedError )
269
-
270
- msg = msg + "|does not support|has no kernel"
263
+ if series .dtype .storage == "pyarrow" :
264
+ import pyarrow as pa
265
+
266
+ # TODO(infer_string)
267
+ # should raise a proper TypeError instead of propagating the pyarrow error
268
+ expected = (expected , pa .lib .ArrowNotImplementedError )
269
+ else :
270
+ expected = (expected , NotImplementedError )
271
+ msg = msg + "|does not support|has no kernel|Cannot perform|cannot perform"
271
272
warn = None if isinstance (func , str ) else FutureWarning
272
273
273
274
with pytest .raises (expected , match = msg ):
0 commit comments