|
1 | 1 | from decimal import Decimal
|
2 | 2 | import operator
|
| 3 | +import re |
3 | 4 |
|
4 | 5 | import numpy as np
|
5 | 6 | import pytest
|
@@ -51,9 +52,13 @@ def test_neg_object(self, df, expected):
|
51 | 52 | ],
|
52 | 53 | )
|
53 | 54 | def test_neg_raises(self, df):
|
54 |
| - with pytest.raises(TypeError): |
| 55 | + msg = ( |
| 56 | + "bad operand type for unary -: 'str'|" |
| 57 | + r"Unary negative expects numeric dtype, not datetime64\[ns\]" |
| 58 | + ) |
| 59 | + with pytest.raises(TypeError, match=msg): |
55 | 60 | (-df)
|
56 |
| - with pytest.raises(TypeError): |
| 61 | + with pytest.raises(TypeError, match=msg): |
57 | 62 | (-df["a"])
|
58 | 63 |
|
59 | 64 | def test_invert(self, float_frame):
|
@@ -116,9 +121,10 @@ def test_pos_object(self, df):
|
116 | 121 | "df", [pd.DataFrame({"a": pd.to_datetime(["2017-01-22", "1970-01-01"])})]
|
117 | 122 | )
|
118 | 123 | def test_pos_raises(self, df):
|
119 |
| - with pytest.raises(TypeError): |
| 124 | + msg = re.escape("Unary plus expects numeric dtype, not datetime64[ns]") |
| 125 | + with pytest.raises(TypeError, match=msg): |
120 | 126 | (+df)
|
121 |
| - with pytest.raises(TypeError): |
| 127 | + with pytest.raises(TypeError, match=msg): |
122 | 128 | (+df["a"])
|
123 | 129 |
|
124 | 130 |
|
@@ -173,12 +179,14 @@ def test_logical_ops_invalid(self):
|
173 | 179 |
|
174 | 180 | df1 = DataFrame(1.0, index=[1], columns=["A"])
|
175 | 181 | df2 = DataFrame(True, index=[1], columns=["A"])
|
176 |
| - with pytest.raises(TypeError): |
| 182 | + msg = re.escape("unsupported operand type(s) for |: 'float' and 'bool'") |
| 183 | + with pytest.raises(TypeError, match=msg): |
177 | 184 | df1 | df2
|
178 | 185 |
|
179 | 186 | df1 = DataFrame("foo", index=[1], columns=["A"])
|
180 | 187 | df2 = DataFrame(True, index=[1], columns=["A"])
|
181 |
| - with pytest.raises(TypeError): |
| 188 | + msg = re.escape("unsupported operand type(s) for |: 'str' and 'bool'") |
| 189 | + with pytest.raises(TypeError, match=msg): |
182 | 190 | df1 | df2
|
183 | 191 |
|
184 | 192 | def test_logical_operators(self):
|
@@ -565,7 +573,11 @@ def test_comp(func):
|
565 | 573 | result = func(df1, df2)
|
566 | 574 | tm.assert_numpy_array_equal(result.values, func(df1.values, df2.values))
|
567 | 575 |
|
568 |
| - with pytest.raises(ValueError, match="dim must be <= 2"): |
| 576 | + msg = ( |
| 577 | + "Unable to coerce to Series/DataFrame, " |
| 578 | + "dimension must be <= 2: (30, 4, 1, 1, 1)" |
| 579 | + ) |
| 580 | + with pytest.raises(ValueError, match=re.escape(msg)): |
569 | 581 | func(df1, ndim_5)
|
570 | 582 |
|
571 | 583 | result2 = func(simple_frame, row)
|
@@ -594,7 +606,8 @@ def test_strings_to_numbers_comparisons_raises(self, compare_operators_no_eq_ne)
|
594 | 606 | )
|
595 | 607 |
|
596 | 608 | f = getattr(operator, compare_operators_no_eq_ne)
|
597 |
| - with pytest.raises(TypeError): |
| 609 | + msg = "'[<>]=?' not supported between instances of 'str' and 'int'" |
| 610 | + with pytest.raises(TypeError, match=msg): |
598 | 611 | f(df, 0)
|
599 | 612 |
|
600 | 613 | def test_comparison_protected_from_errstate(self):
|
@@ -881,9 +894,12 @@ def test_alignment_non_pandas(self):
|
881 | 894 | align(df, val, "columns")
|
882 | 895 |
|
883 | 896 | val = np.zeros((3, 3, 3))
|
884 |
| - with pytest.raises(ValueError): |
| 897 | + msg = re.escape( |
| 898 | + "Unable to coerce to Series/DataFrame, dimension must be <= 2: (3, 3, 3)" |
| 899 | + ) |
| 900 | + with pytest.raises(ValueError, match=msg): |
885 | 901 | align(df, val, "index")
|
886 |
| - with pytest.raises(ValueError): |
| 902 | + with pytest.raises(ValueError, match=msg): |
887 | 903 | align(df, val, "columns")
|
888 | 904 |
|
889 | 905 | def test_no_warning(self, all_arithmetic_operators):
|
|
0 commit comments