Skip to content

TST: GH30999 address all bare pytest.raises in pandas/tests/series and add EMPTY_STRING_PATTERN to tm #38855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/series/apply/test_series_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)