Skip to content

Commit d717eb1

Browse files
Revert "TST: Bare pytest raises" in base extension tests (#38748)
* Revert "TST: Bare pytest raises (#38576)" This reverts commit 9919623.
1 parent 0b7ce00 commit d717eb1

File tree

3 files changed

+10
-69
lines changed

3 files changed

+10
-69
lines changed

pandas/tests/arrays/boolean/test_arithmetic.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_add_mul(left_array, right_array, opname, exp):
4646

4747

4848
def test_sub(left_array, right_array):
49-
with tm.external_error_raised(TypeError):
49+
with pytest.raises(TypeError):
5050
# numpy points to ^ operator or logical_xor function instead
5151
left_array - right_array
5252

@@ -92,29 +92,13 @@ def test_error_invalid_values(data, all_arithmetic_operators):
9292
ops = getattr(s, op)
9393

9494
# invalid scalars
95-
msg = (
96-
"ufunc '\\w+' did not contain a loop with signature matching types|"
97-
"ufunc '\\w+' not supported for the input types, and the inputs could "
98-
"not be safely coerced to any supported types|"
99-
"\\w+ cannot perform the operation \\w+"
100-
)
101-
with pytest.raises(TypeError, match=msg):
95+
with pytest.raises(TypeError):
10296
ops("foo")
103-
104-
msg = (
105-
"unsupported operand type\\(s\\) for|"
106-
"Concatenation operation is not implemented for NumPy arrays"
107-
)
108-
with pytest.raises(TypeError, match=msg):
97+
with pytest.raises(TypeError):
10998
ops(pd.Timestamp("20180101"))
11099

111100
# invalid array-likes
112101
if op not in ("__mul__", "__rmul__"):
113102
# TODO(extension) numpy's mul with object array sees booleans as numbers
114-
msg = (
115-
"unsupported operand type\\(s\\) for|"
116-
'can only concatenate str \\(not "bool"\\) to str|'
117-
"not all arguments converted during string formatting"
118-
)
119-
with pytest.raises(TypeError, match=msg):
103+
with pytest.raises(TypeError):
120104
ops(pd.Series("foo", index=s.index))

pandas/tests/extension/base/ops.py

+4-21
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,7 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
3030
expected = s.combine(other, op)
3131
self.assert_series_equal(result, expected)
3232
else:
33-
msg = (
34-
"unsupported operand type\\(s\\) for|"
35-
"cannot perform [\\w_]+ with this index type: [\\w_]+|"
36-
"Object with dtype category cannot perform the numpy op [\\w_]+|"
37-
"cannot add [\\w_]+ and [\\w_]+|"
38-
"can't multiply sequence by non-int of type '[\\w_]+'|"
39-
'can only concatenate str \\(not "[\\w_]+"\\) to str|'
40-
"Object with dtype category cannot perform the numpy op [\\w_]+|"
41-
"Concatenation operation is not implemented for NumPy arrays"
42-
)
43-
with pytest.raises(exc, match=msg):
33+
with pytest.raises(exc):
4434
op(s, other)
4535

4636
def _check_divmod_op(self, s, op, other, exc=Exception):
@@ -54,12 +44,7 @@ def _check_divmod_op(self, s, op, other, exc=Exception):
5444
self.assert_series_equal(result_div, expected_div)
5545
self.assert_series_equal(result_mod, expected_mod)
5646
else:
57-
msg = (
58-
"'tuple' object has no attribute 'dtype'|"
59-
"cannot perform __r?divmod__ with this index type|"
60-
"unsupported operand type\\(s\\) for divmod\\(\\)"
61-
)
62-
with pytest.raises(exc, match=msg):
47+
with pytest.raises(exc):
6348
divmod(s, other)
6449

6550

@@ -126,8 +111,7 @@ def test_add_series_with_extension_array(self, data):
126111
def test_error(self, data, all_arithmetic_operators):
127112
# invalid ops
128113
op_name = all_arithmetic_operators
129-
msg = "'[\\w_]+' object has no attribute '[\\w_]+'"
130-
with pytest.raises(AttributeError, match=msg):
114+
with pytest.raises(AttributeError):
131115
getattr(data, op_name)
132116

133117
@pytest.mark.parametrize("box", [pd.Series, pd.DataFrame])
@@ -161,8 +145,7 @@ def _compare_other(self, s, data, op_name, other):
161145

162146
# series
163147
s = pd.Series(data)
164-
msg = "not supported between instances of '[\\w._]+' and '[\\w._]+'"
165-
with pytest.raises(TypeError, match=msg):
148+
with pytest.raises(TypeError):
166149
op(s, other)
167150

168151
def test_compare_scalar(self, data, all_compare_operators):

pandas/tests/extension/base/setitem.py

+2-28
Original file line numberDiff line numberDiff line change
@@ -282,25 +282,8 @@ def test_setitem_loc_iloc_slice(self, data):
282282
self.assert_equal(result, expected)
283283

284284
def test_setitem_slice_mismatch_length_raises(self, data):
285-
# This class is a test mixin class, based on which test class it's mixed
286-
# with the expected error messages can vary. This regular expression
287-
# catches all the variants of those messages. It's formatted as a big OR
288-
# statement: /m1|m2|m3|m4/
289-
290-
msg = (
291-
# pandas.core.arrays.period.PeriodArray
292-
# pandas.core.arrays.datetimes.DatetimeArray
293-
"cannot set using a slice indexer with a different length than the value|"
294-
# string_arrow.ArrowStringArray
295-
"Length of indexer and values mismatch|"
296-
# pandas.tests.extension.decimal.array.DecimalArray
297-
"cannot copy sequence with size \\d to array axis with dimension \\d|"
298-
# All the rest
299-
"could not broadcast input array from "
300-
"shape \\(\\d,?\\) into shape \\(\\d,?\\)"
301-
)
302285
arr = data[:5]
303-
with pytest.raises(ValueError, match=msg):
286+
with pytest.raises(ValueError):
304287
arr[:1] = arr[:2]
305288

306289
def test_setitem_slice_array(self, data):
@@ -309,17 +292,8 @@ def test_setitem_slice_array(self, data):
309292
self.assert_extension_array_equal(arr, data[-5:])
310293

311294
def test_setitem_scalar_key_sequence_raise(self, data):
312-
# Check the comment on test_setitem_slice_mismatch_length_raises for more info.
313-
msg = (
314-
# pandas.core.arrays.string_arrow.ArrowStringArray
315-
"Must pass scalars with scalar indexer|"
316-
# pandas.core.arrays.datetimes.DatetimeArray
317-
"Could not convert object to NumPy datetime|"
318-
# All the rest
319-
"setting an array element with a sequence"
320-
)
321295
arr = data[:5].copy()
322-
with pytest.raises(ValueError, match=msg):
296+
with pytest.raises(ValueError):
323297
arr[0] = arr[[0, 1]]
324298

325299
def test_setitem_preserves_views(self, data):

0 commit comments

Comments
 (0)