Skip to content

BUG: Recognize chained fsspec URLs #61041

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

Merged
merged 4 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ I/O
^^^
- Bug in :class:`DataFrame` and :class:`Series` ``repr`` of :py:class:`collections.abc.Mapping`` elements. (:issue:`57915`)
- Bug in :meth:`.DataFrame.to_json` when ``"index"`` was a value in the :attr:`DataFrame.column` and :attr:`Index.name` was ``None``. Now, this will fail with a ``ValueError`` (:issue:`58925`)
- Bug in :meth:`.io.common.is_fsspec_url` not recognizing chained fsspec URLs (:issue:`48978`)
- Bug in :meth:`DataFrame._repr_html_` which ignored the ``"display.float_format"`` option (:issue:`59876`)
- Bug in :meth:`DataFrame.from_records` where ``columns`` parameter with numpy structured array was not reordering and filtering out the columns (:issue:`59717`)
- Bug in :meth:`DataFrame.to_dict` raises unnecessary ``UserWarning`` when columns are not unique and ``orient='tight'``. (:issue:`58281`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

_VALID_URLS = set(uses_relative + uses_netloc + uses_params)
_VALID_URLS.discard("")
_RFC_3986_PATTERN = re.compile(r"^[A-Za-z][A-Za-z0-9+\-+.]*://")
_FSSPEC_URL_PATTERN = re.compile(r"^[A-Za-z][A-Za-z0-9+\-+.]*(::[A-Za-z0-9+\-+.]+)*://")

BaseBufferT = TypeVar("BaseBufferT", bound=BaseBuffer)

Expand Down Expand Up @@ -291,7 +291,7 @@ def is_fsspec_url(url: FilePath | BaseBuffer) -> bool:
"""
return (
isinstance(url, str)
and bool(_RFC_3986_PATTERN.match(url))
and bool(_FSSPEC_URL_PATTERN.match(url))
and not url.startswith(("http://", "https://"))
)

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,7 @@ def test_read_timezone_information(self):
[
"s3://example-fsspec/",
"gcs://another-fsspec/file.json",
"filecache::s3://yet-another-fsspec/file.json",
"https://example-site.com/data",
"some-protocol://data.txt",
],
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ def test_is_fsspec_url():
assert icom.is_fsspec_url("RFC-3986+compliant.spec://something")


def test_is_fsspec_url_chained():
# GH#48978 Support chained fsspec URLs
# See https://filesystem-spec.readthedocs.io/en/latest/features.html#url-chaining.
assert icom.is_fsspec_url("filecache::s3://pandas/test.csv")
assert icom.is_fsspec_url("zip://test.csv::filecache::gcs://bucket/file.zip")
assert icom.is_fsspec_url("filecache::zip://test.csv::gcs://bucket/file.zip")
assert icom.is_fsspec_url("filecache::dask::s3://pandas/test.csv")
assert not icom.is_fsspec_url("filecache:s3://pandas/test.csv")
assert not icom.is_fsspec_url("filecache:::s3://pandas/test.csv")
assert not icom.is_fsspec_url("filecache::://pandas/test.csv")


@pytest.mark.parametrize("encoding", [None, "utf-8"])
@pytest.mark.parametrize("format", ["csv", "json"])
def test_codecs_encoding(encoding, format):
Expand Down