Fix data file patterns starting with "./" for Hub datasets (#7727)#8260
Open
discobot wants to merge 1 commit into
Open
Fix data file patterns starting with "./" for Hub datasets (#7727)#8260discobot wants to merge 1 commit into
discobot wants to merge 1 commit into
Conversation
…ce#7727) Relative patterns like "./data/*.parquet" (e.g. from data_files in YAML configs) were joined with the base path without removing the "." segments. Local loading still worked because LocalFileSystem normalizes paths, but remote filesystems like HfFileSystem treat "." as a literal directory name when globbing, so loading the same dataset from the Hub failed with FileNotFoundError. Now resolve_pattern() strips "." segments from relative patterns before joining them with the base path. Added tests for the local, mock-fs and dataset-repository cases.
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 #7727.
data_filespatterns starting with./raiseFileNotFoundErrorwhen the dataset is loaded from the Hub, even though the same patterns work locally.The asymmetry comes from
resolve_pattern(): it joins relative patterns onto the base path withxjoin(a plainposixpath.join), which keeps the.segments, so the glob pattern ends up ashf://datasets/<repo>/./plain_text/*.parquet.HfFileSystem.glob(like fsspec's generic glob) treats.as a literal directory name and matches nothing, whileLocalFileSystemnormalizes the dot segments away — hence local loading works and Hub loading doesn't.This PR strips
.segments from relative patterns inresolve_pattern()before joining, so./data/*resolves the same asdata/*on every filesystem. The stripping also removes any leading slashes it uncovers (e.g. in.//data/*), so a relative pattern can never turn absolute and resolve outside the base path...segments are left untouched, as before.Added tests for the local, mock-fs and mock-dataset-repository cases (they fail without the fix, no network needed), and checked manually that
resolve_pattern("./plain_text/*.parquet", "hf://datasets/rajpurkar/squad")now resolves the two parquet files instead of raising.