Skip to content

Commit

Permalink
fix correct type inference for cache filesystems (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
hynky1999 authored Jul 22, 2024
1 parent 7349902 commit b5443d2
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit b5443d2

Please sign in to comment.