Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix correct type inference for cached filesystems #257

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/datatrove/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fsspec import open as fsspec_open
from fsspec.callbacks import NoOpCallback, TqdmCallback
from fsspec.core import get_fs_token_paths, strip_protocol, url_to_fs
from fsspec.implementations.cached import CachingFileSystem
from fsspec.implementations.dirfs import DirFileSystem
from fsspec.implementations.local import LocalFileSystem
from huggingface_hub import HfFileSystem, cached_assets_path
Expand Down Expand Up @@ -137,7 +138,7 @@ def list_files(
# makes it slightly easier for file extensions
glob_pattern = f"*{glob_pattern}"
extra_options = {}
if isinstance(self.fs, HfFileSystem):
if isinstance(_get_true_fs(self.fs), HfFileSystem):
extra_options["expand_info"] = False # speed up
if include_directories and not glob_pattern:
extra_options["withdirs"] = True
Expand Down Expand Up @@ -374,3 +375,11 @@ def get_shard_from_paths_file(paths_file: DataFileLike, rank: int, world_size):
for pathi, path in enumerate(f):
if (pathi - rank) % world_size == 0:
yield path.strip()


def _get_true_fs(fs: AbstractFileSystem):
if isinstance(fs, CachingFileSystem):
# We have to unwrap the cached filesystem to get the real fs
return fs.fs

return fs
Loading