Skip to content
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

TST: bare pytest raises #31001

Merged
Merged
Changes from 1 commit
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
32 changes: 25 additions & 7 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,26 @@ def test_constructor(self, which):
c(window=2, min_periods=1, center=False)

# GH 13383
with pytest.raises(ValueError):

msg = "window must be non-negative"

with pytest.raises(ValueError, match=msg):
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
c(0)
c(-1)

# not valid
msg = (
"window must be an integer|"
"passed window foo is not compatible with a datetimelike index|"
"min_periods must be an integer|"
"center must be a boolean"
)
for w in [2.0, "foo", np.array([2])]:
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=msg):
c(window=w)
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=msg):
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
c(window=2, min_periods=w)
with pytest.raises(ValueError):
with pytest.raises(ValueError, match=msg):
c(window=2, min_periods=1, center=w)

@td.skip_if_no_scipy
Expand All @@ -57,7 +66,10 @@ def test_constructor_with_win_type(self, which):
# GH 13383
o = getattr(self, which)
c = o.rolling
with pytest.raises(ValueError):

msg = "window must be > 0"

with pytest.raises(ValueError, match=msg):
c(-1, win_type="boxcar")

@pytest.mark.parametrize("window", [timedelta(days=3), pd.Timedelta(days=3)])
Expand Down Expand Up @@ -113,7 +125,10 @@ def test_numpy_compat(self, method):
def test_closed(self):
df = DataFrame({"A": [0, 1, 2, 3, 4]})
# closed only allowed for datetimelike
with pytest.raises(ValueError):

msg = "losed only implemented for datetimelike and offset based windows"
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved

with pytest.raises(ValueError, match=msg):
df.rolling(window=3, closed="neither")

@pytest.mark.parametrize("closed", ["neither", "left"])
Expand Down Expand Up @@ -296,7 +311,10 @@ def test_iter_raises(self, klass):
# https://github.com/pandas-dev/pandas/issues/11704
# Iteration over a Window
obj = klass([1, 2, 3, 4])
with pytest.raises(NotImplementedError):

msg = "See issue #11704 https://github.com/pandas-dev/pandas/issues/11704"

with pytest.raises(NotImplementedError, match=msg):
iter(obj.rolling(2))

def test_rolling_axis_sum(self, axis_frame):
Expand Down