diff --git a/python/pyspark/pandas/tests/test_rolling.py b/python/pyspark/pandas/tests/test_rolling.py index bf793765655b0..783be4178fbda 100644 --- a/python/pyspark/pandas/tests/test_rolling.py +++ b/python/pyspark/pandas/tests/test_rolling.py @@ -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" diff --git a/python/pyspark/pandas/window.py b/python/pyspark/pandas/window.py index 2808f72fd3c12..ca9dba91d24c7 100644 --- a/python/pyspark/pandas/window.py +++ b/python/pyspark/pandas/window.py @@ -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.