-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
Create fsstore from filesystem #911
Merged
joshmoore
merged 15 commits into
zarr-developers:master
from
rabernat:create-fsstore-from-filesystem
May 4, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2865d53
refactor FSStore class to allow fs argument
rabernat 05cf7a3
add tests
rabernat a5acfbf
fixes #993
rabernat 6756862
add fsspec mapper kwargs to FSMap constructor
rabernat 1b0c084
avoid passing missing_exceptions if possible
rabernat 585e16c
fix line length
rabernat 5b073b4
add tests for array creation with existing fs
rabernat 3ec6855
add test for consolidated reading of unlistable store
rabernat c2ed221
flake8
rabernat d1d8e39
rename functions and skip coverage for workaround we expect to remove
rabernat 0599d4e
update release notes and tutorial
rabernat 36c05ed
fix sphinx ref typo
rabernat c045d52
Merge branch 'master' into create-fsstore-from-filesystem
joshmoore 0cd11c7
Fix use of store.update()
joshmoore c1c9255
Flake8 corrections
joshmoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1262,8 +1262,9 @@ class FSStore(Store): | |
Parameters | ||
---------- | ||
url : str | ||
The destination to map. Should include protocol and path, | ||
like "s3://bucket/root" | ||
The destination to map. If no fs is provided, should include protocol | ||
martindurant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
and path, like "s3://bucket/root". If an fs is provided, can be a path | ||
within that filesystem, like "bucket/root" | ||
normalize_keys : bool | ||
key_separator : str | ||
public API for accessing dimension_separator. Never `None` | ||
|
@@ -1275,7 +1276,19 @@ class FSStore(Store): | |
as a missing key | ||
dimension_separator : {'.', '/'}, optional | ||
Separator placed between the dimensions of a chunk. | ||
storage_options : passed to the fsspec implementation | ||
fs : fsspec.spec.AbstractFileSystem, optional | ||
An existing filesystem to use for the store. | ||
check : bool, optional | ||
If True, performs a touch at the root location, to check for write access. | ||
Passed to `fsspec.mapping.FSMap` constructor. | ||
create : bool, optional | ||
If True, performs a mkdir at the rool location. | ||
Passed to `fsspec.mapping.FSMap` constructor. | ||
missing_exceptions : sequence of Exceptions, optional | ||
Exceptions classes to associate with missing files. | ||
Passed to `fsspec.mapping.FSMap` constructor. | ||
storage_options : passed to the fsspec implementation. Cannot be used | ||
martindurant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
together with fs. | ||
""" | ||
_array_meta_key = array_meta_key | ||
_group_meta_key = group_meta_key | ||
|
@@ -1285,18 +1298,37 @@ def __init__(self, url, normalize_keys=False, key_separator=None, | |
mode='w', | ||
exceptions=(KeyError, PermissionError, IOError), | ||
dimension_separator=None, | ||
fs=None, | ||
check=False, | ||
create=False, | ||
missing_exceptions=None, | ||
**storage_options): | ||
import fsspec | ||
self.normalize_keys = normalize_keys | ||
|
||
protocol, _ = fsspec.core.split_protocol(url) | ||
# set auto_mkdir to True for local file system | ||
if protocol in (None, "file") and not storage_options.get("auto_mkdir"): | ||
storage_options["auto_mkdir"] = True | ||
mapper_options = {"check": check, "create": create} | ||
# https://github.com/zarr-developers/zarr-python/pull/911#discussion_r841926292 | ||
# Some fsspec implementations don't accept missing_exceptions. | ||
martindurant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# This is a workaround to avoid passing it in the most common scenarios. | ||
# Remove this and add missing_exceptions to mapper_options when fsspec is released. | ||
if missing_exceptions is not None: | ||
mapper_options["missing_exceptions"] = missing_exceptions # pragma: no cover | ||
|
||
if fs is None: | ||
protocol, _ = fsspec.core.split_protocol(url) | ||
# set auto_mkdir to True for local file system | ||
if protocol in (None, "file") and not storage_options.get("auto_mkdir"): | ||
storage_options["auto_mkdir"] = True | ||
self.map = fsspec.get_mapper(url, **{**mapper_options, **storage_options}) | ||
self.fs = self.map.fs # for direct operations | ||
self.path = self.fs._strip_protocol(url) | ||
else: | ||
if storage_options: | ||
raise ValueError("Cannot specify both fs and storage_options") | ||
self.fs = fs | ||
self.path = self.fs._strip_protocol(url) | ||
self.map = self.fs.get_mapper(self.path, **mapper_options) | ||
|
||
self.map = fsspec.get_mapper(url, **storage_options) | ||
self.fs = self.map.fs # for direct operations | ||
self.path = self.fs._strip_protocol(url) | ||
self.normalize_keys = normalize_keys | ||
self.mode = mode | ||
self.exceptions = exceptions | ||
# For backwards compatibility. Guaranteed to be non-None | ||
|
@@ -1308,8 +1340,6 @@ def __init__(self, url, normalize_keys=False, key_separator=None, | |
|
||
# Pass attributes to array creation | ||
self._dimension_separator = dimension_separator | ||
if self.fs.exists(self.path) and not self.fs.isdir(self.path): | ||
raise FSPathExistNotDir(url) | ||
Comment on lines
-1311
to
-1312
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. To fix #993 I have simply removed this check... |
||
|
||
def _default_key_separator(self): | ||
if self.key_separator is None: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Although 2.11.3 has been released, I noted that the docs had not been updated, so I added it here.
It seems we have skipped release 2.11.2?
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.
Those releases are coming from the
2_11
branch. (See the related #898 (comment))I assume you intend this for release as a 2.11.x?
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.
Sorry I have clearly not been able to follow that discussion. After reading, I now understand the situation better. Let's discuss at today's SC meeting.
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.
Please ping this thread with any decision on which branch to merge into
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.
@martindurant : @rabernat seemed to think it was ok to hold off on @grlee77's upcoming v3 configuration fix, i.e. this can stay on the branch it is and be released as something
>2.11.x
. If it looks like we want it in a quick~=2.11.x
release, I can attempt the backport.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.
I will do whatever the other devs recommend here (either backport to 2.11.x or put this in 2.12.0)
I am confused about how we will maintain a consistent changelog for these two branches. So I am standing by for advice.