Repository navigation
Conversation
SlidingWindowChunking accepted any step. A step bigger than window_size left the words between two windows in no chunk at all, and a non-positive step made the loop body never run, so the trailing-window branch raised UnboundLocalError on `i`. Validate both arguments up front and initialise the loop cursor so the trailing branch cannot depend on the loop running.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
SlidingWindowChunkingaccepted anystep, which produced two failure modes:step > window_size— the windows never touch, so the words in the gap belong to no chunk and are silently lost:step <= 0—range(..., 0)is empty, so the loop variableiis never bound and the trailing-window branch raisesUnboundLocalError: cannot access local variable 'i'before returning anything.Fix
Validate
window_sizeandstepin__init__(window_size >= 1,1 <= step <= window_size) and initialise the loop cursor so the trailing branch no longer depends on the loop having run.OverlappingWindowChunkingalready rejectsoverlap >= window_sizefor the same reason, so this keeps the two window strategies consistent.How it was checked
tests/general/test_sliding_window_chunking.py(8 tests): every word must land in some chunk for several(window_size, step)pairs, both invalid steps raiseValueError, and text shorter than the window is returned unchanged.pytest tests/general/test_sliding_window_chunking.py→ 8 passed.developfile before the change.