Skip to content

TST: insert 'match' to bare pytest raises in pandas/tests/indexing/te… #36809

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

Merged
merged 1 commit into from
Oct 2, 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
15 changes: 10 additions & 5 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def test_setitem_ndarray_1d(self):
df["bar"] = np.zeros(10, dtype=complex)

# invalid
with pytest.raises(ValueError):
msg = (
"cannot set using a multi-index selection "
"indexer with a different length than the value"
)
with pytest.raises(ValueError, match=msg):
df.loc[df.index[2:5], "bar"] = np.array([2.33j, 1.23 + 0.1j, 2.2, 1.0])

# valid
Expand All @@ -48,7 +52,8 @@ def test_setitem_ndarray_1d(self):
df["foo"] = np.zeros(10, dtype=np.float64)
df["bar"] = np.zeros(10, dtype=complex)

with pytest.raises(ValueError):
msg = "Must have equal len keys and value when setting with an iterable"
with pytest.raises(ValueError, match=msg):
df[2:5] = np.arange(1, 4) * 1j

@pytest.mark.parametrize(
Expand Down Expand Up @@ -1055,13 +1060,13 @@ def test_1tuple_without_multiindex():
def test_duplicate_index_mistyped_key_raises_keyerror():
# GH#29189 float_index.get_loc(None) should raise KeyError, not TypeError
ser = pd.Series([2, 5, 6, 8], index=[2.0, 4.0, 4.0, 5.0])
with pytest.raises(KeyError):
with pytest.raises(KeyError, match="None"):
ser[None]

with pytest.raises(KeyError):
with pytest.raises(KeyError, match="None"):
ser.index.get_loc(None)

with pytest.raises(KeyError):
with pytest.raises(KeyError, match="None"):
ser.index._engine.get_loc(None)


Expand Down