fix(dataset): resolve relative sample files on Windows and filesystem URIs (#4502)#4525
Open
Anai-Guo wants to merge 1 commit into
Open
fix(dataset): resolve relative sample files on Windows and filesystem URIs (#4502)#4525Anai-Guo wants to merge 1 commit into
Anai-Guo wants to merge 1 commit into
Conversation
… URIs (UKGovernmentBEIS#4502) `json_dataset()` / `csv_dataset()` stored `Dataset.location` with `os.path.abspath()`, while `resolve_sample_files()` derived the parent directory by splitting that value on the fsspec filesystem separator. Two problems follow: * On Windows `abspath()` produces backslashes but `LocalFileSystem.sep` is `/`, so the split yields no parent and relative sample files were left unresolved. * `os.path.abspath()` treats `file://`, `s3://` and other filesystem URIs as local path strings, corrupting the stored location. Use the existing filesystem-aware helpers instead: `absolute_file_path()` to build the location (it preserves URI schemes and only resolves genuine relative paths) and `dirname()` to derive the parent directory. Adds a regression test covering a `file://` dataset location.
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 #4502.
Problem
json_dataset()andcsv_dataset()storeDataset.locationwithos.path.abspath(), whileresolve_sample_files()derives the parent directory by splitting that value on the fsspec filesystem separator:Two things go wrong:
abspath()returns backslashes butLocalFileSystem.sepis/, so the split finds no separator,parent_dirbecomes"", and the candidate path/images/ballons.pngdoes not exist — the sample file is silently left relative.os.path.abspath()treatsfile:///s3://as local path strings and corrupts the location before any resolution happens.Verification
Reproduced and verified on Windows 11 / Python 3.12 against the real package.
Before (both fail):
After: both pass.
Fix
Use the filesystem-aware helpers that already exist in
inspect_ai._util.file:absolute_file_path()for the location — it preserves URI schemes and only resolves genuinely relative local paths.dirname()for the parent directory — it is protocol- and separator-aware (verified againsts3://b/sub/d.jsonl→s3://b/sub,file:///c/x/d.jsonl→file:///c/x,C:\x\d.jsonl→C:\x).import osbecomes unused in both readers and is removed.Adds a regression test (
test_dataset_image_paths_file_uri) covering afile://dataset location; the pre-existingtest_dataset_image_pathscovers the Windows local-path case and now passes on Windows.Verified no regression in the plain
csv_dataset/json_dataset/file_datasetread paths.🤖 Generated with Claude Code