Repository navigation
Conversation
SlidingWindows checked that size was positive but not period. A zero period failed with a bare ZeroDivisionError, and a negative period built a window function whose assign() returned no windows, silently dropping every element. Reject a non-positive period with a ValueError, as FixedWindows and Sessions already do for their size.
There was a problem hiding this comment.
📋 Review Summary
This PR adds validation to SlidingWindows.__init__ to ensure the period parameter is strictly positive, preventing ZeroDivisionError when period == 0 and silent element dropping when period < 0. The implementation and accompanying unit test are clean, accurate, and consistent with existing parameter validation in FixedWindows and Sessions.
🔍 General Feedback
- The validation logic and error message match existing conventions across
apache_beam/transforms/window.py. - Unit tests in
window_test.pyappropriately cover both zero and negativeperiodvalues.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @shunping for label python. This pull request likely touches a core component ("core" label). Please review with scrutiny. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
SlidingWindows.__init__in the Python SDK checks thatsizeis positive but never checksperiod.With
period=0the constructor fails onTimestamp.of(offset) % periodwithZeroDivisionError: integer modulo by zero(window.py:479 before this change). With a negative period, for exampleSlidingWindows(size=10, period=-5), it constructs fine andassign()returns[], because therange(...)inassignsteps the wrong way. A pipeline using it drops every element without any error.FixedWindows(size=0)andSessions(gap_size=0)already raiseValueError('The size parameter must be strictly positive.'), and the JavaSlidingWindowsrejects this through its0 <= offset < periodcheck. I added the matching check forperiodright after thesizecheck:Testing: I added
test_sliding_windows_non_positive_periodtowindow_test.py. Before the change it fails withZeroDivisionError: integer modulo by zeroat window.py:479. It also asserts thatFixedWindows(size=0)raisesValueError, which passes before and after. After the changewindow_test.pypasses (20 passed), and thesliding or windowtests insideinputs_test.pyandtrigger_manager_test.pypass (12 passed). In the repo,yaml_provider.pyand the Nexmark queries passperiodfrom user or config values. A zero period already failed there, and a negative one produced no windows, so it now fails with the clear error. I did not runcombiners_test.py,util_test.pyorpipeline_test.pylocally, since my venv lackspyhamcrestandmock, and I did not run the full CI.