diff --git a/pandas/tests/extension/base/getitem.py b/pandas/tests/extension/base/getitem.py index 251376798efc3..bfd6da0fc864d 100644 --- a/pandas/tests/extension/base/getitem.py +++ b/pandas/tests/extension/base/getitem.py @@ -160,11 +160,12 @@ def test_getitem_mask(self, data): def test_getitem_mask_raises(self, data): mask = np.array([True, False]) - with pytest.raises(IndexError): + msg = f"Boolean index has wrong length: 2 instead of {len(data)}" + with pytest.raises(IndexError, match=msg): data[mask] mask = pd.array(mask, dtype="boolean") - with pytest.raises(IndexError): + with pytest.raises(IndexError, match=msg): data[mask] def test_getitem_boolean_array_mask(self, data): @@ -305,7 +306,9 @@ def test_take_empty(self, data, na_value, na_cmp): result = empty.take([-1], allow_fill=True) assert na_cmp(result[0], na_value) - with pytest.raises(IndexError): + msg = "cannot do a non-empty take from an empty axes|out of bounds" + + with pytest.raises(IndexError, match=msg): empty.take([-1]) with pytest.raises(IndexError, match="cannot do a non-empty take"): @@ -330,13 +333,14 @@ def test_take_non_na_fill_value(self, data_missing): self.assert_extension_array_equal(result, expected) def test_take_pandas_style_negative_raises(self, data, na_value): - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=""): data.take([0, -2], fill_value=na_value, allow_fill=True) @pytest.mark.parametrize("allow_fill", [True, False]) def test_take_out_of_bounds_raises(self, data, allow_fill): arr = data[:3] - with pytest.raises(IndexError): + + with pytest.raises(IndexError, match="out of bounds|out-of-bounds"): arr.take(np.asarray([0, 3]), allow_fill=allow_fill) def test_take_series(self, data): diff --git a/pandas/tests/extension/base/reduce.py b/pandas/tests/extension/base/reduce.py index 6f433d659575a..55f8aca1b8ae0 100644 --- a/pandas/tests/extension/base/reduce.py +++ b/pandas/tests/extension/base/reduce.py @@ -28,7 +28,12 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna): op_name = all_numeric_reductions s = pd.Series(data) - with pytest.raises(TypeError): + msg = ( + "[Cc]annot perform|Categorical is not ordered for operation|" + "'Categorical' does not implement reduction|" + ) + + with pytest.raises(TypeError, match=msg): getattr(s, op_name)(skipna=skipna) @pytest.mark.parametrize("skipna", [True, False]) @@ -36,7 +41,12 @@ def test_reduce_series_boolean(self, data, all_boolean_reductions, skipna): op_name = all_boolean_reductions s = pd.Series(data) - with pytest.raises(TypeError): + msg = ( + "[Cc]annot perform|Categorical is not ordered for operation|" + "'Categorical' does not implement reduction|" + ) + + with pytest.raises(TypeError, match=msg): getattr(s, op_name)(skipna=skipna)