Skip to content
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

Refactor: store mode and initialization #2442

Merged
merged 35 commits into from
Nov 13, 2024

Conversation

jhamman
Copy link
Member

@jhamman jhamman commented Oct 28, 2024

Previously, opening a store in w mode, had a side effect (Store.clear). That was leading to unexpected behavior when a path argument was also supplied. This refactor takes the following approach:

  • keeps Store.mode but allows this to be only StoreAccessMode = Literal["r", "w"]
  • replaces Store.mode with Store.read_only
  • removes any side effect when opening a store.
  • adds StorePath.open(..., mode: AccessModeLiteral) where side effects can be applied at the path level

builds on #2430
closes #2359

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

Copy link
Member Author

@jhamman jhamman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes to guide review

Comment on lines 32 to 33
assert mode in ("r", "w")
self._mode = mode
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may consider a different setting here (e.g. readonly)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer the attribute matching the parameter name.

We can have a property

@property
def readonly(self): return self.mode == "r"

Edit: which I see you have down below.

src/zarr/abc/store.py Outdated Show resolved Hide resolved
src/zarr/api/asynchronous.py Outdated Show resolved Hide resolved
src/zarr/api/asynchronous.py Outdated Show resolved Hide resolved
src/zarr/api/asynchronous.py Outdated Show resolved Hide resolved
src/zarr/storage/common.py Outdated Show resolved Hide resolved
src/zarr/abc/store.py Outdated Show resolved Hide resolved
@jhamman jhamman marked this pull request as ready for review November 8, 2024 14:09
src/zarr/abc/store.py Outdated Show resolved Hide resolved
src/zarr/abc/store.py Outdated Show resolved Hide resolved
src/zarr/api/asynchronous.py Outdated Show resolved Hide resolved
src/zarr/api/asynchronous.py Outdated Show resolved Hide resolved
src/zarr/abc/store.py Outdated Show resolved Hide resolved
@jhamman jhamman merged commit e49647b into zarr-developers:main Nov 13, 2024
26 checks passed
@jhamman jhamman deleted the refactor/store-mode branch November 13, 2024 00:51
@jhamman
Copy link
Member Author

jhamman commented Nov 13, 2024

Thanks folks for the reviews here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v3] Re-opening an existing RemoteStore V3 group causes the first child to be deleted
4 participants