Skip to content

Commit 1835064

Browse files
ShaharNavehsimonjayhawkins
authored andcommitted
TST: bare pytest raises (#31001)
1 parent d78c061 commit 1835064

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

pandas/tests/window/test_rolling.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,34 @@ def test_constructor(self, which):
3232
c = o.rolling
3333

3434
# valid
35+
c(0)
3536
c(window=2)
3637
c(window=2, min_periods=1)
3738
c(window=2, min_periods=1, center=True)
3839
c(window=2, min_periods=1, center=False)
3940

4041
# GH 13383
41-
with pytest.raises(ValueError):
42-
c(0)
42+
43+
msg = "window must be non-negative"
44+
45+
with pytest.raises(ValueError, match=msg):
4346
c(-1)
4447

4548
# not valid
4649
for w in [2.0, "foo", np.array([2])]:
47-
with pytest.raises(ValueError):
50+
msg = (
51+
"window must be an integer|"
52+
"passed window foo is not compatible with a datetimelike index"
53+
)
54+
with pytest.raises(ValueError, match=msg):
4855
c(window=w)
49-
with pytest.raises(ValueError):
56+
57+
msg = "min_periods must be an integer"
58+
with pytest.raises(ValueError, match=msg):
5059
c(window=2, min_periods=w)
51-
with pytest.raises(ValueError):
60+
61+
msg = "center must be a boolean"
62+
with pytest.raises(ValueError, match=msg):
5263
c(window=2, min_periods=1, center=w)
5364

5465
@td.skip_if_no_scipy
@@ -57,7 +68,10 @@ def test_constructor_with_win_type(self, which):
5768
# GH 13383
5869
o = getattr(self, which)
5970
c = o.rolling
60-
with pytest.raises(ValueError):
71+
72+
msg = "window must be > 0"
73+
74+
with pytest.raises(ValueError, match=msg):
6175
c(-1, win_type="boxcar")
6276

6377
@pytest.mark.parametrize("window", [timedelta(days=3), pd.Timedelta(days=3)])
@@ -113,7 +127,10 @@ def test_numpy_compat(self, method):
113127
def test_closed(self):
114128
df = DataFrame({"A": [0, 1, 2, 3, 4]})
115129
# closed only allowed for datetimelike
116-
with pytest.raises(ValueError):
130+
131+
msg = "closed only implemented for datetimelike and offset based windows"
132+
133+
with pytest.raises(ValueError, match=msg):
117134
df.rolling(window=3, closed="neither")
118135

119136
@pytest.mark.parametrize("closed", ["neither", "left"])
@@ -296,7 +313,10 @@ def test_iter_raises(self, klass):
296313
# https://github.com/pandas-dev/pandas/issues/11704
297314
# Iteration over a Window
298315
obj = klass([1, 2, 3, 4])
299-
with pytest.raises(NotImplementedError):
316+
317+
msg = "See issue #11704 https://github.com/pandas-dev/pandas/issues/11704"
318+
319+
with pytest.raises(NotImplementedError, match=msg):
300320
iter(obj.rolling(2))
301321

302322
def test_rolling_axis_sum(self, axis_frame):

0 commit comments

Comments
 (0)