diff --git a/fsspec/implementations/arrow.py b/fsspec/implementations/arrow.py index 3b1048acd..7b84dc5c7 100644 --- a/fsspec/implementations/arrow.py +++ b/fsspec/implementations/arrow.py @@ -61,6 +61,20 @@ def protocol(self): def fsid(self): return "hdfs_" + tokenize(self.fs.host, self.fs.port) + @classmethod + def from_fs(cls, fs, **kwargs): + override = {"local": "file"} + type_name = override.get(fs.type_name, fs.type_name) + + try: + fs.from_uri(f"{type_name}:///") + root_marker = "/" + except BaseException: + root_marker = "" + + wrapper = type(cls.__name__, (cls,), {"root_marker": root_marker}) + return wrapper(fs, **kwargs) + @classmethod def _strip_protocol(cls, path): ops = infer_storage_options(path) diff --git a/fsspec/implementations/tests/test_arrow.py b/fsspec/implementations/tests/test_arrow.py index 6150b03ec..0f3ab825f 100644 --- a/fsspec/implementations/tests/test_arrow.py +++ b/fsspec/implementations/tests/test_arrow.py @@ -241,3 +241,17 @@ def test_seekable(fs, remote_dir): with fs.open(remote_dir + "/a.txt", "rb", seekable=False) as file: with pytest.raises(OSError): file.seek(5) + + +@pytest.mark.parametrize( + ["filesystem", "root_marker"], + [ + (pyarrow_fs.LocalFileSystem(), "/"), + (pyarrow_fs.S3FileSystem(), ""), + (pyarrow_fs.GcsFileSystem(), ""), + ], +) +def test_from_fs(filesystem, root_marker): + wrapper = ArrowFSWrapper.from_fs(filesystem) + assert wrapper.root_marker == root_marker + assert wrapper.__class__.root_marker == root_marker