Skip to content
Open
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
4 changes: 4 additions & 0 deletions python/pyspark/pandas/tests/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def test_rolling_error(self):
ps.range(10).rolling(window=-1)
with self.assertRaisesRegex(ValueError, "min_periods must be >= 0"):
ps.range(10).rolling(window=1, min_periods=-1)
with self.assertRaisesRegex(ValueError, "window must be an integer"):
ps.range(10).rolling(window=1.1)
with self.assertRaisesRegex(ValueError, "min_periods must be an integer"):
ps.range(10).rolling(window=1, min_periods=-1.1)

with self.assertRaisesRegex(
TypeError, "psdf_or_psser must be a series or dataframe; however, got:.*int"
Expand Down
9 changes: 7 additions & 2 deletions python/pyspark/pandas/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ def __init__(
window: int,
min_periods: Optional[int] = None,
):
if type(window) is not int:
raise ValueError("window must be an integer")
if window < 0:
raise ValueError("window must be >= 0")
if (min_periods is not None) and (min_periods < 0):
raise ValueError("min_periods must be >= 0")
if min_periods is not None:
if type(min_periods) is not int:
raise ValueError("min_periods must be an integer")
if min_periods < 0:
raise ValueError("min_periods must be >= 0")
if min_periods is None:
# TODO: 'min_periods' is not equivalent in pandas because it does not count NA as
# a value.
Expand Down