1212import numpy as np
1313import pytest
1414
15- from pandas ._config import using_string_dtype
16-
17- from pandas .compat import HAS_PYARROW
1815from pandas .errors import SpecificationError
1916
2017from pandas import (
@@ -212,10 +209,6 @@ def transform(row):
212209 data .apply (transform , axis = 1 )
213210
214211
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- )
219212@pytest .mark .parametrize (
220213 "df, func, expected" ,
221214 tm .get_cython_table_params (
@@ -225,21 +218,25 @@ def transform(row):
225218def test_agg_cython_table_raises_frame (df , func , expected , axis , using_infer_string ):
226219 # GH 21224
227220 if using_infer_string :
228- import pyarrow as pa
221+ if df .dtypes .iloc [0 ].storage == "pyarrow" :
222+ import pyarrow as pa
229223
230- expected = (expected , pa .lib .ArrowNotImplementedError )
224+ # TODO(infer_string)
225+ # should raise a proper TypeError instead of propagating the pyarrow error
231226
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+ )
233234 warn = None if isinstance (func , str ) else FutureWarning
234235 with pytest .raises (expected , match = msg ):
235236 with tm .assert_produces_warning (warn , match = "using DataFrame.cumprod" ):
236237 df .agg (func , axis = axis )
237238
238239
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- )
243240@pytest .mark .parametrize (
244241 "series, func, expected" ,
245242 chain (
@@ -263,11 +260,15 @@ def test_agg_cython_table_raises_series(series, func, expected, using_infer_stri
263260 msg = r"Cannot convert \['a' 'b' 'c'\] to numeric"
264261
265262 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"
271272 warn = None if isinstance (func , str ) else FutureWarning
272273
273274 with pytest .raises (expected , match = msg ):
0 commit comments