diff --git a/pandas/tests/io/pytables/test_complex.py b/pandas/tests/io/pytables/test_complex.py index 3a7aff3b551c2..71bb6584889aa 100644 --- a/pandas/tests/io/pytables/test_complex.py +++ b/pandas/tests/io/pytables/test_complex.py @@ -149,8 +149,17 @@ def test_complex_indexing_error(setup_path): {"A": [1, 2, 3, 4], "B": ["a", "b", "c", "d"], "C": complex128}, index=list("abcd"), ) + + msg = ( + "Columns containing complex values can be stored " + "but cannot be indexed when using table format. " + "Either use fixed format, set index=False, " + "or do not include the columns containing complex " + "values to data_columns when initializing the table." + ) + with ensure_clean_store(setup_path) as store: - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): store.append("df", df, data_columns=["C"]) @@ -158,8 +167,16 @@ def test_complex_series_error(setup_path): complex128 = np.array([1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j, 1.0 + 1.0j]) s = Series(complex128, index=list("abcd")) + msg = ( + "Columns containing complex values can be stored " + "but cannot be indexed when using table format. " + "Either use fixed format, set index=False, " + "or do not include the columns containing complex " + "values to data_columns when initializing the table." + ) + with ensure_clean_path(setup_path) as path: - with pytest.raises(TypeError): + with pytest.raises(TypeError, match=msg): s.to_hdf(path, "obj", format="t") with ensure_clean_path(setup_path) as path: diff --git a/pandas/tests/io/test_clipboard.py b/pandas/tests/io/test_clipboard.py index fca98175a0a24..440c370857eef 100644 --- a/pandas/tests/io/test_clipboard.py +++ b/pandas/tests/io/test_clipboard.py @@ -238,10 +238,11 @@ def test_read_clipboard_infer_excel(self, request, mock_clipboard): tm.assert_frame_equal(res, exp) def test_invalid_encoding(self, df): + msg = "clipboard only supports utf-8 encoding" # test case for testing invalid encoding - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): df.to_clipboard(encoding="ascii") - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=msg): pd.read_clipboard(encoding="ascii") @pytest.mark.parametrize("enc", ["UTF-8", "utf-8", "utf8"]) diff --git a/pandas/tests/plotting/frame/test_frame_subplots.py b/pandas/tests/plotting/frame/test_frame_subplots.py index 427b2c1c3a180..2e0eecbeaacaa 100644 --- a/pandas/tests/plotting/frame/test_frame_subplots.py +++ b/pandas/tests/plotting/frame/test_frame_subplots.py @@ -218,9 +218,13 @@ def test_subplots_layout_multi_column(self): self._check_axes_shape(axes, axes_num=3, layout=(4, 1)) assert axes.shape == (4, 1) - with pytest.raises(ValueError): + msg = "Layout of 1x1 must be larger than required size 3" + + with pytest.raises(ValueError, match=msg): df.plot(subplots=True, layout=(1, 1)) - with pytest.raises(ValueError): + + msg = "At least one dimension of layout must be positive" + with pytest.raises(ValueError, match=msg): df.plot(subplots=True, layout=(-1, -1)) @pytest.mark.parametrize( @@ -272,7 +276,9 @@ def test_subplots_multiple_axes(self): self._check_axes_shape(axes, axes_num=6, layout=(2, 3)) tm.close() - with pytest.raises(ValueError): + msg = "The number of passed axes must be 3, the same as the output plot" + + with pytest.raises(ValueError, match=msg): fig, axes = self.plt.subplots(2, 3) # pass different number of axes from required df.plot(subplots=True, ax=axes)