-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Support async FSMap objects in zarr.open #2774
base: main
Are you sure you want to change the base?
Changes from all commits
656a565
877eb80
90cc08d
f04145c
825cd6e
c4bfb06
06f35f2
e792e01
ed11018
e586001
3f9a34c
4d1bd26
4b7a5eb
abc5fdf
5d8e8ca
cb2db7d
ed9639f
46e8bff
a126d4b
50c18f0
7517f72
3ae719b
d4d2256
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 | ||||
---|---|---|---|---|---|---|
@@ -1,5 +1,7 @@ | ||||||
from __future__ import annotations | ||||||
|
||||||
import importlib | ||||||
import importlib.util | ||||||
import json | ||||||
from pathlib import Path | ||||||
from typing import TYPE_CHECKING, Any, Literal | ||||||
|
@@ -12,6 +14,10 @@ | |||||
from zarr.storage._memory import MemoryStore | ||||||
from zarr.storage._utils import normalize_path | ||||||
|
||||||
_has_fsspec = importlib.util.find_spec("fsspec") | ||||||
if _has_fsspec: | ||||||
from fsspec.mapping import FSMap | ||||||
|
||||||
if TYPE_CHECKING: | ||||||
from zarr.core.buffer import BufferPrototype | ||||||
|
||||||
|
@@ -228,7 +234,7 @@ | |||||
|
||||||
|
||||||
async def make_store_path( | ||||||
store_like: StoreLike | None, | ||||||
store_like: StoreLike | FSMap | None, | ||||||
*, | ||||||
path: str | None = "", | ||||||
mode: AccessModeLiteral | None = None, | ||||||
|
@@ -311,9 +317,18 @@ | |||||
# We deliberate only consider dict[str, Buffer] here, and not arbitrary mutable mappings. | ||||||
# By only allowing dictionaries, which are in-memory, we know that MemoryStore appropriate. | ||||||
store = await MemoryStore.open(store_dict=store_like, read_only=_read_only) | ||||||
elif _has_fsspec: | ||||||
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
Suggested change
and then you fall to the same exception in |
||||||
if not isinstance(store_like, FSMap): | ||||||
raise (TypeError(f"Unsupported type for store_like: '{type(store_like).__name__}'")) | ||||||
if path: | ||||||
raise ValueError("'path' was provided but is not used for FSMap store_like objects") | ||||||
if storage_options: | ||||||
raise ValueError( | ||||||
"'storage_options was provided but is not used for FSMap store_like objects" | ||||||
) | ||||||
store = FsspecStore.from_mapper(store_like, read_only=_read_only) | ||||||
else: | ||||||
msg = f"Unsupported type for store_like: '{type(store_like).__name__}'" # type: ignore[unreachable] | ||||||
raise TypeError(msg) | ||||||
raise (TypeError(f"Unsupported type for store_like: '{type(store_like).__name__}'")) | ||||||
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. The linter requires the redundant outer parentheses? 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. Apparently this is not covered; switching the condition as I suggested above would make it so, or making a test explicitly with a bad type of store. 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'll check on the linter issue, as for the bad coverage I think we still need this in case fsspec isn't installed. #2872 should fix the code coverage gap, but it's taking longer than I expected to finish that PR because it uncovered other issues with the test matrix design (I'm working on it but might not finish today) |
||||||
|
||||||
result = await StorePath.open(store, path=path_normalized, mode=mode) | ||||||
|
||||||
|
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.
Doesn't this fail if fsspec isn't present, because FSMap isn't imported? Maybe you need
or make fsspec a required dependency.