Skip to content

Commit 61ae774

Browse files
authored
TST: GH30999 address all bare pytest.raises in pandas/tests/series and add EMPTY_STRING_PATTERN to tm (#38855)
1 parent 2a17bf3 commit 61ae774

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

pandas/_testing/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130

131131
NULL_OBJECTS = [None, np.nan, pd.NaT, float("nan"), pd.NA]
132132

133+
EMPTY_STRING_PATTERN = re.compile("^$")
133134

134135
# set testing_mode
135136
_testing_mode_warnings = (DeprecationWarning, ResourceWarning)

pandas/tests/series/apply/test_series_apply.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ def test_agg_cython_table_transform(self, series, func, expected):
454454
)
455455
def test_agg_cython_table_raises(self, series, func, expected):
456456
# GH21224
457-
with pytest.raises(expected):
457+
msg = r"[Cc]ould not convert|can't multiply sequence by non-int of type"
458+
with pytest.raises(expected, match=msg):
458459
# e.g. Series('a b'.split()).cumprod() will raise
459460
series.agg(func)
460461

@@ -714,7 +715,7 @@ def test_map_categorical(self):
714715
tm.assert_series_equal(result, exp)
715716
assert result.dtype == object
716717

717-
with pytest.raises(NotImplementedError):
718+
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
718719
s.map(lambda x: x, na_action="ignore")
719720

720721
def test_map_datetimetz(self):
@@ -737,7 +738,7 @@ def test_map_datetimetz(self):
737738
exp = Series(list(range(24)) + [0], name="XX", dtype=np.int64)
738739
tm.assert_series_equal(result, exp)
739740

740-
with pytest.raises(NotImplementedError):
741+
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
741742
s.map(lambda x: x, na_action="ignore")
742743

743744
# not vectorized

pandas/tests/series/test_ufunc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,5 @@ def test_outer():
300300
s = pd.Series([1, 2, 3])
301301
o = np.array([1, 2, 3])
302302

303-
with pytest.raises(NotImplementedError):
303+
with pytest.raises(NotImplementedError, match=tm.EMPTY_STRING_PATTERN):
304304
np.subtract.outer(s, o)

0 commit comments

Comments
 (0)