-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
Allow mode casting for Store
s
#2249
Conversation
src/zarr/store/zip.py
Outdated
@@ -115,6 +117,11 @@ async def empty(self) -> bool: | |||
else: | |||
return True | |||
|
|||
def with_mode(self, mode: ZipStoreAccessModeLiteral) -> Self: # type: ignore[override] | |||
return type(self)( |
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.
This probably needs some work... would we want the new Store to share the same Lock?
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.
This wasn't straightforward to implement, because of a need to close the old ZipStore (and writing the ending records) before opening the new store.
For now I've opted to raise NotImplementedError for ZipStore.
Store
sStore
s
The GPU test failed. I think that's because at zarr-python/src/zarr/store/memory.py Lines 170 to 171 in 692593b
store.with_mode('r') no longer views the same dict as the first store.
@akshaysubr I suspect that those lines are there to ensure that all of the values in the dictionary are GPU buffers. What do you think about documenting that as a requirement to use the store (and maybe narrowing the type of the dict values in |
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.
Thanks @TomAugspurger -- a few suggestions but this is great.
cc @d-v-b who was also looking at this problem today.
second this, once those suggestions are integrated then I think this will be a great addition. |
It's tangentially related, but I wanted to confirm that people are OK with changing the |
cc @akshaysubr |
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.
This looks good to me @TomAugspurger - some failing tests in GPU land but otherwise looks good to me.
|
||
def __str__(self) -> str: | ||
return f"gpumemory://{id(self._store_dict)}" | ||
|
||
def __repr__(self) -> str: | ||
return f"GpuMemoryStore({str(self)!r})" | ||
|
||
@classmethod | ||
def from_dict(cls, store_dict: MutableMapping[str, Buffer]) -> Self: |
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 like this API!
pre-commit.ci autofix |
Following the discussion in #2186 (comment), this is a POC for opening "reopening" a store with a new mode.
The semantics are that reopening a store with a new mode should return a new Store that's backed by the same underlying data.
AFAICT, our current stores use / enforce
mode
"logically". There's nothing about the actual underlying store that's readonly whenmode="r"
. You could imagine some cases where it's not possible to cast between modes (e.g. you have a readonly database connection). I think it's fine for those Stores to handle that.By default, the method is abstract meaning this is a new bit of code required for stores to implement. We could also raise
NotImplementedError
by default.TODO: