Skip to content
Prev Previous commit
Next Next commit
fix tests: update the error message
  • Loading branch information
natmokval committed Dec 17, 2025
commit efa0017ab1e96844f99c7d06cf3f4a9ca185673f
5 changes: 3 additions & 2 deletions pandas/tests/frame/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,10 @@ def test_getitem_setitem_integer_slice_keyerrors(self):

# non-monotonic, raise KeyError
df2 = df.iloc[list(range(5)) + list(range(5, 10))[::-1]]
with pytest.raises(KeyError, match=r"^3$"):
msg = "non-monotonic index with a non-specific label: 3"
with pytest.raises(KeyError, match=msg):
df2.loc[3:11]
with pytest.raises(KeyError, match=r"^3$"):
with pytest.raises(KeyError, match=msg):
df2.loc[3:11] = 0

def test_fancy_getitem_slice_mixed(self, float_frame, float_string_frame):
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/indexes/numeric/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,11 @@ def test_slice_locs_na(self):

def test_slice_locs_na_raises(self):
index = Index([np.nan, 1, 2])
with pytest.raises(KeyError, match="1.5"):
msg = "non-monotonic index with a non-specific label: 1.5"
with pytest.raises(KeyError, match=msg):
index.slice_locs(start=1.5)

with pytest.raises(KeyError, match="1.5"):
with pytest.raises(KeyError, match=msg):
index.slice_locs(end=1.5)


Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3162,9 +3162,10 @@ def test_loc_getitem_setitem_integer_slice_keyerrors(self):

# non-monotonic, raise KeyError
s2 = ser.iloc[list(range(5)) + list(range(9, 4, -1))]
with pytest.raises(KeyError, match=r"^3$"):
msg = "non-monotonic index with a non-specific label: 3"
with pytest.raises(KeyError, match=msg):
s2.loc[3:11]
with pytest.raises(KeyError, match=r"^3$"):
with pytest.raises(KeyError, match=msg):
s2.loc[3:11] = 0

def test_loc_getitem_iterator(self, string_series):
Expand Down
Loading