Skip to content

Commit f5ef132

Browse files
authored
TST: GH30999 Add match=msg to all pytest.raises in pandas/tests/reshape (#38800)
1 parent 7323d19 commit f5ef132

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pandas/tests/reshape/test_get_dummies.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import numpy as np
24
import pytest
35

@@ -30,7 +32,8 @@ def effective_dtype(self, dtype):
3032
return dtype
3133

3234
def test_get_dummies_raises_on_dtype_object(self, df):
33-
with pytest.raises(ValueError):
35+
msg = "dtype=object is not a valid dtype for get_dummies"
36+
with pytest.raises(ValueError, match=msg):
3437
get_dummies(df, dtype="object")
3538

3639
def test_get_dummies_basic(self, sparse, dtype):
@@ -296,11 +299,19 @@ def test_dataframe_dummies_prefix_sep(self, df, sparse):
296299
tm.assert_frame_equal(result, expected)
297300

298301
def test_dataframe_dummies_prefix_bad_length(self, df, sparse):
299-
with pytest.raises(ValueError):
302+
msg = re.escape(
303+
"Length of 'prefix' (1) did not match the length of the columns being "
304+
"encoded (2)"
305+
)
306+
with pytest.raises(ValueError, match=msg):
300307
get_dummies(df, prefix=["too few"], sparse=sparse)
301308

302309
def test_dataframe_dummies_prefix_sep_bad_length(self, df, sparse):
303-
with pytest.raises(ValueError):
310+
msg = re.escape(
311+
"Length of 'prefix_sep' (1) did not match the length of the columns being "
312+
"encoded (2)"
313+
)
314+
with pytest.raises(ValueError, match=msg):
304315
get_dummies(df, prefix_sep=["bad"], sparse=sparse)
305316

306317
def test_dataframe_dummies_prefix_dict(self, sparse):

pandas/tests/reshape/test_union_categoricals.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ def test_union_categoricals_sort(self):
275275

276276
c1 = Categorical(["b", "a"], categories=["b", "a", "c"], ordered=True)
277277
c2 = Categorical(["a", "c"], categories=["b", "a", "c"], ordered=True)
278-
with pytest.raises(TypeError):
278+
msg = "Cannot use sort_categories=True with ordered Categoricals"
279+
with pytest.raises(TypeError, match=msg):
279280
union_categoricals([c1, c2], sort_categories=True)
280281

281282
def test_union_categoricals_sort_false(self):
@@ -344,5 +345,6 @@ def test_union_categorical_unwrap(self):
344345
result = union_categoricals([c1, c2])
345346
tm.assert_categorical_equal(result, expected)
346347

347-
with pytest.raises(TypeError):
348+
msg = "all components to combine must be Categorical"
349+
with pytest.raises(TypeError, match=msg):
348350
union_categoricals([c1, ["a", "b", "c"]])

0 commit comments

Comments
 (0)