AI junk - #2238
Closed
Swastikbhat-lab wants to merge 1 commit into
Closed
Conversation
The `slice` filter appends `fill_with` to every chunk when the slice count divides the iterable length exactly, because the padding condition `slice_number >= slices_with_extra` is true for all chunks when `slices_with_extra` is 0. Only pad chunks when there are short chunks to pad, i.e. when the length is not evenly divisible by the slice count. Add a regression test for the divisor case. Closes pallets#2118.
Member
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.
Fixes #2118.
Bug
When the slice count divides the iterable length evenly, the
slicefilter still pads every chunk withfill_with:Actual:
[[1, 'foo'], [2, 'foo'], [3, 'foo'], [4, 'foo']]Expected:
[[1], [2], [3], [4]]Cause
In
sync_do_slice, the padding condition isslice_number >= slices_with_extra. Whenlength % slices == 0,slices_with_extrais 0, so the condition is true for every chunk and each one getsfill_withappended — even though no chunk is short.Fix
Only pad when there are short chunks to pad, i.e. when
slices_with_extrais non-zero. The non-divisor behavior (padding the chunks after the extras, e.g.range(10)|slice(3, 'X')→[[0, 1, 2, 3], [4, 5, 6, 'X'], [7, 8, 9, 'X']]) is unchanged.Tests
Added a regression test for the divisor case. Full suite: