fix: index_adjustment_after_clean_extra_whitespace maps cleaned index to the wrong original offset - #4413
Open
lntutor wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Shadow auto-approve: would auto-approve. Fixes a sign bug in index adjustment mapping; bounded fix with regression test.
Re-trigger cubic
… to wrong original offset index_adjustment_after_clean_extra_whitespace subtracts the moved distance when it must add it. moved_indices[i] is the number of characters removed before cleaned index i (per clean_extra_whitespace_ with_index_run's docstring), so the original position of a cleaned character is index + moved_indices[index]. Subtracting maps every character following a collapsed whitespace run to the wrong -- or a negative -- original index (e.g. 'B' at cleaned index 8 mapped to 4, a space, instead of 12). Change the operator and add a round-trip regression test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N6RtoHuxrDqTUo9Mw9h4Cv
lntutor
force-pushed
the
fix/index-adjustment-whitespace-sign
branch
from
July 27, 2026 14:14
2a6bdd7 to
fcb0467
Compare
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's broken
index_adjustment_after_clean_extra_whitespacesubtracts the moved distance when it must add it:clean_extra_whitespace_with_index_runreturnsmoved_indiceswheremoved_indices[i]is the number of characters removed before cleaned indexi(per its docstring), so the original position of a cleaned character isindex + moved_indices[index]. Subtracting maps every character following a collapsed whitespace run to the wrong — or a negative — original offset:Only
+round-trips (text[i + moved[i]] == cleaned[i]) for every kept character, including multi-run cases like"a b c".Fix
Change the operator to
+and add a round-trip regression test. (Distinct from #4166, which optimized the producerclean_extra_whitespace_with_index_runand left this sign bug untouched.)Tests
Adds
test_index_adjustment_maps_cleaned_index_back_to_original. Fulltest_unstructured/cleaners/test_core.pypasses (89).