diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 24359809065b1..897f4ab59c370 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -130,6 +130,7 @@ NULL_OBJECTS = [None, np.nan, pd.NaT, float("nan"), pd.NA] +EMPTY_STRING_PATTERN = re.compile("^$") # set testing_mode _testing_mode_warnings = (DeprecationWarning, ResourceWarning) diff --git a/pandas/tests/series/apply/test_series_apply.py b/pandas/tests/series/apply/test_series_apply.py index 5935d0c81af88..1242126c19527 100644 --- a/pandas/tests/series/apply/test_series_apply.py +++ b/pandas/tests/series/apply/test_series_apply.py @@ -454,7 +454,8 @@ def test_agg_cython_table_transform(self, series, func, expected): ) def test_agg_cython_table_raises(self, series, func, expected): # GH21224 - with pytest.raises(expected): + msg = r"[Cc]ould not convert|can't multiply sequence by non-int of type" + with pytest.raises(expected, match=msg): # e.g. Series('a b'.split()).cumprod() will raise series.agg(func) @@ -714,7 +715,7 @@ def test_map_categorical(self): tm.assert_series_equal(result, exp) assert result.dtype == object - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN): s.map(lambda x: x, na_action="ignore") def test_map_datetimetz(self): @@ -737,7 +738,7 @@ def test_map_datetimetz(self): exp = Series(list(range(24)) + [0], name="XX", dtype=np.int64) tm.assert_series_equal(result, exp) - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN): s.map(lambda x: x, na_action="ignore") # not vectorized diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index 271ac31d303ae..a5aa319e4772f 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -300,5 +300,5 @@ def test_outer(): s = pd.Series([1, 2, 3]) o = np.array([1, 2, 3]) - with pytest.raises(NotImplementedError): + with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN): np.subtract.outer(s, o)