Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: GH30999 Add match=msg to all pytest.raises in pandas/tests/reshape #38800

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pandas/tests/reshape/test_get_dummies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import numpy as np
import pytest

Expand Down Expand Up @@ -30,7 +32,8 @@ def effective_dtype(self, dtype):
return dtype

def test_get_dummies_raises_on_dtype_object(self, df):
with pytest.raises(ValueError):
msg = "dtype=object is not a valid dtype for get_dummies"
with pytest.raises(ValueError, match=msg):
get_dummies(df, dtype="object")

def test_get_dummies_basic(self, sparse, dtype):
Expand Down Expand Up @@ -296,11 +299,19 @@ def test_dataframe_dummies_prefix_sep(self, df, sparse):
tm.assert_frame_equal(result, expected)

def test_dataframe_dummies_prefix_bad_length(self, df, sparse):
with pytest.raises(ValueError):
msg = re.escape(
"Length of 'prefix' (1) did not match the length of the columns being "
"encoded (2)"
)
with pytest.raises(ValueError, match=msg):
get_dummies(df, prefix=["too few"], sparse=sparse)

def test_dataframe_dummies_prefix_sep_bad_length(self, df, sparse):
with pytest.raises(ValueError):
msg = re.escape(
"Length of 'prefix_sep' (1) did not match the length of the columns being "
"encoded (2)"
)
with pytest.raises(ValueError, match=msg):
get_dummies(df, prefix_sep=["bad"], sparse=sparse)

def test_dataframe_dummies_prefix_dict(self, sparse):
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/reshape/test_union_categoricals.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def test_union_categoricals_sort(self):

c1 = Categorical(["b", "a"], categories=["b", "a", "c"], ordered=True)
c2 = Categorical(["a", "c"], categories=["b", "a", "c"], ordered=True)
with pytest.raises(TypeError):
msg = "Cannot use sort_categories=True with ordered Categoricals"
with pytest.raises(TypeError, match=msg):
union_categoricals([c1, c2], sort_categories=True)

def test_union_categoricals_sort_false(self):
Expand Down Expand Up @@ -344,5 +345,6 @@ def test_union_categorical_unwrap(self):
result = union_categoricals([c1, c2])
tm.assert_categorical_equal(result, expected)

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