Fix find_offset treating exact start-boundary as 'not found'#290
Open
Chessing234 wants to merge 1 commit intoallenai:mainfrom
Open
Fix find_offset treating exact start-boundary as 'not found'#290Chessing234 wants to merge 1 commit intoallenai:mainfrom
Chessing234 wants to merge 1 commit intoallenai:mainfrom
Conversation
scripts/find_offset.py treats each metadata row as the half-open
interval [start, end). After the bisect + 'not exact match' decrement,
loc points at the row whose start is <= offset, so the validity check is:
if data.iloc[loc].start >= offset or data.iloc[loc].end <= offset:
raise ValueError(f"Offset {offset} not found in {opts.file}.")
The left side uses >= instead of >. When the requested offset lands
exactly on a row boundary (offset == start) that row is actually the
correct one -- the first byte of the document begins at start -- but
the check raises ValueError and aborts before locs.append(loc).
Using > matches the half-open semantics (offset in [start, end)) and
keeps the 'offset >= end' side unchanged, so the only behaviour change
is that offsets exactly on a start boundary are now correctly reported
as found instead of failing.
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.
Bug
scripts/find_offset.pyaborts withValueError: Offset N not found in ...whenever the requested offset lands exactly on a document's starting byte — even though the offset is valid and the surrounding code has already chosen the right row:Root cause
Each row in the metadata CSV describes a document occupying the half-open byte interval
[start, end). After thebisect+ "not exact match" decrement,locis the row whosestart <= offset. So to decide "not found" we needoffset < start(impossible here) oroffset >= end, i.e.The existing check uses
start >= offset, which isTruewheneveroffset == start— the boundary case. That fires theValueErrorfor a perfectly valid offset sitting at the first byte of a document.Why the fix is correct
Changing
>=to>aligns the check with the half-open interval semantics the rest of the script already uses:offset == start: still inside[start, end)→ no longer raises (start > offsetisFalse,end <= offsetis alsoFalsebecauseend > start == offset).offset == end: already correctly flagged as not found, unchanged (end <= offsetisTrue).startandend: unchanged.One-character edit (
>=→>) on the single offending line; no change to thebisect/ decrement logic above it or the downstreamlocs.append(loc)path.