Skip to content

Commit a521ecc

Browse files
krajatclRajat Bishnoi
and
Rajat Bishnoi
authored
TST: insert 'match' to bare pytest raises in pandas/tests/indexing/test_indexing.py (#36809)
Co-authored-by: Rajat Bishnoi <rajat.b@greyorange.com>
1 parent 4de9b5b commit a521ecc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pandas/tests/indexing/test_indexing.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ def test_setitem_ndarray_1d(self):
3131
df["bar"] = np.zeros(10, dtype=complex)
3232

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

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

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

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

1061-
with pytest.raises(KeyError):
1066+
with pytest.raises(KeyError, match="None"):
10621067
ser.index.get_loc(None)
10631068

1064-
with pytest.raises(KeyError):
1069+
with pytest.raises(KeyError, match="None"):
10651070
ser.index._engine.get_loc(None)
10661071

10671072

0 commit comments

Comments
 (0)