Skip to content

Commit

Permalink
only capture unrecognized filesystem errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Dec 20, 2024
1 parent af32337 commit b9c635d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
24 changes: 14 additions & 10 deletions python/pyarrow/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,22 @@ def _resolve_filesystem_and_path(path, filesystem=None, *, memory_map=False):
try:
filesystem, path = FileSystem.from_uri(path)
except ValueError as e:
try:
import fsspec
except ImportError:
# neither an URI nor a locally existing path, so assume that
# local path was given and propagate a nicer file not found error
# instead of a more confusing scheme parsing error
if "empty scheme" not in str(e) \
and "Cannot parse URI" not in str(e):
msg = str(e)
if "Unrecognized filesystem type" in msg:
# try loading fsspec to handle not recognized filesystems
try:
import fsspec
fs, path = fsspec.url_to_fs(path)
filesystem = _ensure_filesystem(fs)
except (ImportError, ValueError):
raise e
elif "empty scheme" in msg or "Cannot parse URI" in msg:
# neither an URI nor a locally existing path, so assume that
# local path was given and propagate a nicer file not found
# error instead of a more confusing scheme parsing error
pass
else:
fs, path = fsspec.url_to_fs(path)
filesystem = _ensure_filesystem(fs)
raise e
else:
path = filesystem.normalize_path(path)

Expand Down
4 changes: 4 additions & 0 deletions python/pyarrow/tests/parquet/test_parquet_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,7 @@ def test_parquet_file_fsspec_fallback():
pq.write_table(table, "memory://example.parquet")
table2 = pq.read_table("memory://example.parquet")
assert table.equals(table2)

msg = "Unrecognized filesystem type in URI"
with pytest.raises(pa.ArrowInvalid, match=msg):
pq.read_table("non-existing://example.parquet")

0 comments on commit b9c635d

Please sign in to comment.