-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improve http url glob error #9930
base: main
Are you sure you want to change the base?
Changes from all commits
01e7518
83e553b
e44326d
4e4eeb0
d858059
d377780
3132f6a
900eef5
4c4462f
5b9b749
51be61f
ae314d1
06088c2
d2617ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
NdimSizeLenMixin, | ||
attempt_import, | ||
emit_user_level_warning, | ||
is_http_url, | ||
is_remote_uri, | ||
) | ||
from xarray.namedarray.parallelcompat import get_chunked_array_type | ||
|
@@ -143,28 +144,31 @@ def _find_absolute_paths( | |
['common.py'] | ||
""" | ||
if isinstance(paths, str): | ||
if is_remote_uri(paths) and kwargs.get("engine") == "zarr": | ||
if TYPE_CHECKING: | ||
import fsspec | ||
if is_remote_uri(paths): | ||
if not is_http_url(paths): | ||
# remote uris that are not http are likely s3 or similar, which support globbing with fsspec | ||
|
||
if TYPE_CHECKING: | ||
import fsspec | ||
else: | ||
fsspec = attempt_import("fsspec") | ||
|
||
fs, _, _ = fsspec.core.get_fs_token_paths( | ||
paths, | ||
mode="rb", | ||
storage_options=kwargs.get("backend_kwargs", {}).get( | ||
"storage_options", {} | ||
), | ||
expand=False, | ||
) | ||
tmp_paths = fs.glob(fs._strip_protocol(paths)) # finds directories | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could pass detail=True, and then filter for directories |
||
return [fs.get_mapper(path) for path in tmp_paths] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought zarr, in particular, didn't wan't mappers any more, but Store objects, or URLs that will be immediately converted to Stores within zarr anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jhamman has the recommendation changed here recently? |
||
else: | ||
fsspec = attempt_import("fsspec") | ||
|
||
fs, _, _ = fsspec.core.get_fs_token_paths( | ||
paths, | ||
mode="rb", | ||
storage_options=kwargs.get("backend_kwargs", {}).get( | ||
"storage_options", {} | ||
), | ||
expand=False, | ||
) | ||
tmp_paths = fs.glob(fs._strip_protocol(paths)) # finds directories | ||
return [fs.get_mapper(path) for path in tmp_paths] | ||
elif is_remote_uri(paths): | ||
raise ValueError( | ||
"cannot do wild-card matching for paths that are remote URLs " | ||
f"unless engine='zarr' is specified. Got paths: {paths}. " | ||
"Instead, supply paths as an explicit list of strings." | ||
) | ||
raise ValueError( | ||
"cannot do wild-card matching for paths that are remote http URLs. " | ||
f"Got paths: {paths}. " | ||
"Instead, supply paths as an explicit list of strings." | ||
) | ||
else: | ||
return sorted(glob(_normalize_path(paths))) | ||
elif isinstance(paths, os.PathLike): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be url_to_fs these days, as it's more user-facing.