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: add message matches to pytest.raises in test_duplicate_labels.py GH30999 #37114

Merged
merged 1 commit into from
Oct 14, 2020
Merged
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
28 changes: 18 additions & 10 deletions pandas/tests/generic/test_duplicate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def test_set_flags_with_duplicates(self, cls, axes):
result = cls(**axes)
assert result.flags.allows_duplicate_labels is True

with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
cls(**axes).set_flags(allows_duplicate_labels=False)

@pytest.mark.parametrize(
Expand All @@ -287,7 +288,8 @@ def test_set_flags_with_duplicates(self, cls, axes):
],
)
def test_setting_allows_duplicate_labels_raises(self, data):
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
data.flags.allows_duplicate_labels = False

assert data.flags.allows_duplicate_labels is True
Expand All @@ -297,7 +299,8 @@ def test_setting_allows_duplicate_labels_raises(self, data):
)
def test_series_raises(self, func):
s = pd.Series([0, 1], index=["a", "b"]).set_flags(allows_duplicate_labels=False)
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
func(s)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -332,7 +335,8 @@ def test_getitem_raises(self, getter, target):
else:
target = df

with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
getter(target)

@pytest.mark.parametrize(
Expand All @@ -352,7 +356,8 @@ def test_getitem_raises(self, getter, target):
],
)
def test_concat_raises(self, objs, kwargs):
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.concat(objs, **kwargs)

@not_implemented
Expand All @@ -361,7 +366,8 @@ def test_merge_raises(self):
allows_duplicate_labels=False
)
b = pd.DataFrame({"B": [0, 1, 2]}, index=["a", "b", "b"])
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.merge(a, b, left_index=True, right_index=True)


Expand All @@ -381,13 +387,14 @@ def test_merge_raises(self):
ids=lambda x: type(x).__name__,
)
def test_raises_basic(idx):
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.Series(1, index=idx).set_flags(allows_duplicate_labels=False)

with pytest.raises(pd.errors.DuplicateLabelError):
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.DataFrame({"A": [1, 1]}, index=idx).set_flags(allows_duplicate_labels=False)

with pytest.raises(pd.errors.DuplicateLabelError):
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.DataFrame([[1, 2]], columns=idx).set_flags(allows_duplicate_labels=False)


Expand All @@ -412,7 +419,8 @@ def test_format_duplicate_labels_message_multi():

def test_dataframe_insert_raises():
df = pd.DataFrame({"A": [1, 2]}).set_flags(allows_duplicate_labels=False)
with pytest.raises(ValueError, match="Cannot specify"):
msg = "Cannot specify"
with pytest.raises(ValueError, match=msg):
df.insert(0, "A", [3, 4], allow_duplicates=True)


Expand Down