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 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
36 changes: 28 additions & 8 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,34 @@ def test_constructor(self, which):
c = o.rolling

# valid
c(0)
c(window=2)
c(window=2, min_periods=1)
c(window=2, min_periods=1, center=True)
c(window=2, min_periods=1, center=False)

# GH 13383
with pytest.raises(ValueError):
c(0)

msg = "window must be non-negative"

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

# not valid
for w in [2.0, "foo", np.array([2])]:
with pytest.raises(ValueError):
msg = (
"window must be an integer|"
"passed window foo is not compatible with a datetimelike index"
)
with pytest.raises(ValueError, match=msg):
c(window=w)
with pytest.raises(ValueError):

msg = "min_periods must be an integer"
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):

msg = "center must be a boolean"
with pytest.raises(ValueError, match=msg):
c(window=2, min_periods=1, center=w)

@td.skip_if_no_scipy
Expand All @@ -57,7 +68,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 +127,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 = "closed only implemented for datetimelike and offset based windows"

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

@pytest.mark.parametrize("closed", ["neither", "left"])
Expand Down Expand Up @@ -296,7 +313,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