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
2 changes: 2 additions & 0 deletions sdks/python/apache_beam/transforms/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ def __init__(
):
if size <= 0:
raise ValueError('The size parameter must be strictly positive.')
if period <= 0:
raise ValueError('The period parameter must be strictly positive.')
self.size = Duration.of(size)
self.period = Duration.of(period)
self.offset = Timestamp.of(offset) % period
Expand Down
8 changes: 8 additions & 0 deletions sdks/python/apache_beam/transforms/window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def test_sliding_windows_assignment_fraction_large_offset(self):
self.assertEqual([IntervalWindow(4.0, 7.5), IntervalWindow(1.5, 5.0)],
windowfn.assign(context('v', 4.5)))

def test_sliding_windows_non_positive_period(self):
# Control: the sibling window function already rejects a non-positive size.
with self.assertRaises(ValueError):
FixedWindows(size=0)
for period in (0, -5):
with self.assertRaisesRegex(ValueError, 'period'):
SlidingWindows(size=10, period=period)

def test_sessions_merging(self):
windowfn = Sessions(10)

Expand Down
Loading