Skip to content

Commit 42b77db

Browse files
remove xfails + update expected error msgs
1 parent fb4f99f commit 42b77db

File tree

4 files changed

+35
-55
lines changed

4 files changed

+35
-55
lines changed

pandas/tests/apply/test_invalid_arg.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import numpy as np
1313
import pytest
1414

15-
from pandas._config import using_string_dtype
16-
17-
from pandas.compat import HAS_PYARROW
1815
from pandas.errors import SpecificationError
1916

2017
from 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):
225218
def 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):

pandas/tests/frame/test_reductions.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ def test_stat_op_api_float_string_frame(self, float_string_frame, axis, opname):
276276
msg = "'[><]=' not supported between instances of 'float' and 'str'"
277277
elif opname == "median":
278278
msg = re.compile(
279-
r"Cannot convert \[.*\] to numeric|does not support", flags=re.S
279+
r"Cannot convert \[.*\] to numeric|does not support|Cannot perform",
280+
flags=re.S,
280281
)
281282
if not isinstance(msg, re.Pattern):
282-
msg = msg + "|does not support"
283+
msg = msg + "|does not support|Cannot perform reduction"
283284
with pytest.raises(TypeError, match=msg):
284285
getattr(float_string_frame, opname)(axis=axis)
285286
if opname != "nunique":
@@ -441,20 +442,13 @@ def test_mixed_ops(self, op):
441442
"could not convert",
442443
"can't multiply sequence by non-int",
443444
"does not support",
445+
"Cannot perform",
444446
]
445447
)
446448
with pytest.raises(TypeError, match=msg):
447449
getattr(df, op)()
448450

449451
with pd.option_context("use_bottleneck", False):
450-
msg = "|".join(
451-
[
452-
"Could not convert",
453-
"could not convert",
454-
"can't multiply sequence by non-int",
455-
"does not support",
456-
]
457-
)
458452
with pytest.raises(TypeError, match=msg):
459453
getattr(df, op)()
460454

pandas/tests/groupby/transform/test_transform.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pandas._config import using_string_dtype
77

88
from pandas._libs import lib
9-
from pandas.compat import HAS_PYARROW
109

1110
from pandas.core.dtypes.common import ensure_platform_int
1211

@@ -385,10 +384,7 @@ def test_transform_nuisance_raises(df, using_infer_string):
385384
gbc = grouped["B"]
386385
msg = "Could not convert"
387386
if using_infer_string:
388-
if df.columns.dtype.storage == "pyarrow":
389-
msg = "with dtype str does not support operation 'mean'"
390-
else:
391-
msg = "Cannot perform reduction 'mean' with string dtype"
387+
msg = "Cannot perform reduction 'mean' with string dtype"
392388
with pytest.raises(TypeError, match=msg):
393389
gbc.transform(lambda x: np.mean(x))
394390

@@ -483,10 +479,7 @@ def test_groupby_transform_with_int(using_infer_string):
483479
)
484480
msg = "Could not convert"
485481
if using_infer_string:
486-
if HAS_PYARROW:
487-
msg = "with dtype str does not support operation 'mean'"
488-
else:
489-
msg = "Cannot perform reduction 'mean' with string dtype"
482+
msg = "Cannot perform reduction 'mean' with string dtype"
490483
with np.errstate(all="ignore"):
491484
with pytest.raises(TypeError, match=msg):
492485
df.groupby("A").transform(lambda x: (x - x.mean()) / x.std())

pandas/tests/series/test_reductions.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas._config import using_string_dtype
5-
6-
from pandas.compat import HAS_PYARROW
7-
84
import pandas as pd
95
from pandas import Series
106
import pandas._testing as tm
@@ -171,48 +167,44 @@ def test_mean_with_convertible_string_raises():
171167
ser = Series(["1", "2"])
172168
assert ser.sum() == "12"
173169

174-
msg = "Could not convert string '12' to numeric|does not support"
170+
msg = "Could not convert string '12' to numeric|does not support|Cannot perform"
175171
with pytest.raises(TypeError, match=msg):
176172
ser.mean()
177173

178174
df = ser.to_frame()
179-
msg = r"Could not convert \['12'\] to numeric|does not support"
175+
msg = r"Could not convert \['12'\] to numeric|does not support|Cannot perform"
180176
with pytest.raises(TypeError, match=msg):
181177
df.mean()
182178

183179

184-
@pytest.mark.xfail(
185-
using_string_dtype() and not HAS_PYARROW, reason="TODO(infer_string)"
186-
)
187180
def test_mean_dont_convert_j_to_complex():
188181
# GH#36703
189182
df = pd.DataFrame([{"db": "J", "numeric": 123}])
190-
msg = r"Could not convert \['J'\] to numeric|does not support"
183+
msg = r"Could not convert \['J'\] to numeric|does not support|Cannot perform"
191184
with pytest.raises(TypeError, match=msg):
192185
df.mean()
193186

194187
with pytest.raises(TypeError, match=msg):
195188
df.agg("mean")
196189

197-
msg = "Could not convert string 'J' to numeric|does not support"
190+
msg = "Could not convert string 'J' to numeric|does not support|Cannot perform"
198191
with pytest.raises(TypeError, match=msg):
199192
df["db"].mean()
200-
msg = "Could not convert string 'J' to numeric|ufunc 'divide'"
193+
msg = "Could not convert string 'J' to numeric|ufunc 'divide'|Cannot perform"
201194
with pytest.raises(TypeError, match=msg):
202195
np.mean(df["db"].astype("string").array)
203196

204197

205-
@pytest.mark.xfail(
206-
using_string_dtype() and not HAS_PYARROW, reason="TODO(infer_string)"
207-
)
208198
def test_median_with_convertible_string_raises():
209199
# GH#34671 this _could_ return a string "2", but definitely not float 2.0
210-
msg = r"Cannot convert \['1' '2' '3'\] to numeric|does not support"
200+
msg = r"Cannot convert \['1' '2' '3'\] to numeric|does not support|Cannot perform"
211201
ser = Series(["1", "2", "3"])
212202
with pytest.raises(TypeError, match=msg):
213203
ser.median()
214204

215-
msg = r"Cannot convert \[\['1' '2' '3'\]\] to numeric|does not support"
205+
msg = (
206+
r"Cannot convert \[\['1' '2' '3'\]\] to numeric|does not support|Cannot perform"
207+
)
216208
df = ser.to_frame()
217209
with pytest.raises(TypeError, match=msg):
218210
df.median()

0 commit comments

Comments
 (0)