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

fix file modes #2000

Merged
merged 27 commits into from
Jul 26, 2024
Merged

fix file modes #2000

merged 27 commits into from
Jul 26, 2024

Conversation

brokkoli71
Copy link
Member

fixes #1978
according to docstrings of zarr.open the modes should do:

mode : {'r', 'r+', 'a', 'w', 'w-'}, optional
        Persistence mode: 'r' means read only (must exist); 'r+' means
        read/write (must exist); 'a' means read/write (create if doesn't
        exist); 'w' means create (overwrite if exists); 'w-' means create
        (fail if exists).

this PR implements and tests this behavior, so #1978 gets fixed

@normanrz normanrz added the V3 Affects the v3 branch label Jun 27, 2024
@normanrz normanrz added this to the 3.0.0 milestone Jun 27, 2024
@normanrz normanrz requested a review from jhamman June 27, 2024 13:12
src/zarr/abc/store.py Outdated Show resolved Hide resolved
src/zarr/abc/store.py Outdated Show resolved Hide resolved
@jhamman
Copy link
Member

jhamman commented Jul 1, 2024

Thanks @brokkoli71 for picking this up. What is the expected behavior of mode='w'? Should we have a Store.clear() method that we call in these cases?

@brokkoli71
Copy link
Member Author

Thanks @brokkoli71 for picking this up. What is the expected behavior of mode='w'? Should we have a Store.clear() method that we call in these cases?

good point, according to the docstrings: 'w' means create (overwrite if exists). So yes, would be probably a good idea to have a generalized Store.clear. I will have a look at that

@d-v-b
Copy link
Contributor

d-v-b commented Jul 2, 2024

I agree that a method for clearing a store is a good idea. Just bear in mind that this can be a performance bottleneck when deleting arrays with a lot of chunks, especially on remote storage. We should think about performance at some point.

@brokkoli71
Copy link
Member Author

I agree that a method for clearing a store is a good idea. Just bear in mind that this can be a performance bottleneck when deleting arrays with a lot of chunks, especially on remote storage. We should think about performance at some point.

I was wondering, if supporting mode='w' as create (overwrite if exists) is a good idea concerning the performance? what is the usecase of this mode? maybe it would be better to explicitly have a delete or clear method? or we should have a warning in the docstrings?

@d-v-b
Copy link
Contributor

d-v-b commented Jul 3, 2024

I agree that a method for clearing a store is a good idea. Just bear in mind that this can be a performance bottleneck when deleting arrays with a lot of chunks, especially on remote storage. We should think about performance at some point.

I was wondering, if supporting mode='w' as create (overwrite if exists) is a good idea concerning the performance? what is the usecase of this mode? maybe it would be better to explicitly have a delete or clear method? or we should have a warning in the docstrings?

There's a lot of usage for create + overwrite -- if users are rapidly iterating on something, they already created an old array, but they want to save a new array with the same name + different datatype, then the easiest way to do this is via something like an overwrite option. Handling this via array the creation flow is more ergonomic than forcing users to go through a separate API.

Don't worry too much about the performance concerns with bulk deletion for now. We should make the API convenient, then worry about performance later. I only brought delete performance up because it's something that zarr python v2 didn't deal with, which caused me some headaches.

src/zarr/abc/store.py Outdated Show resolved Hide resolved
# Conflicts:
#	tests/v3/conftest.py
#	tests/v3/test_codecs.py
@brokkoli71 brokkoli71 requested a review from jhamman July 5, 2024 11:53
Copy link
Member

@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.

this is looking great! Just a few final comments.

tests/v3/test_api.py Outdated Show resolved Hide resolved
src/zarr/abc/store.py Outdated Show resolved Hide resolved
src/zarr/abc/store.py Outdated Show resolved Hide resolved
@brokkoli71 brokkoli71 requested a review from jhamman July 18, 2024 13:40
Copy link
Member

@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.

One last comment and a suggestion on ensure_open that you can take or leave. Thanks again for pushing on this.

src/zarr/abc/store.py Outdated Show resolved Hide resolved
src/zarr/abc/store.py Show resolved Hide resolved
@jhamman
Copy link
Member

jhamman commented Jul 25, 2024

@brokkoli71 - happy to merge this if you can resolve the conflicts.

# Conflicts:
#	src/zarr/store/remote.py
@joshmoore
Copy link
Member

Sadly still conflicting, @brokkoli71

# Conflicts:
#	src/zarr/store/core.py
#	tests/v3/test_store/test_memory.py
@normanrz normanrz merged commit 325786a into zarr-developers:v3 Jul 26, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V3 Affects the v3 branch
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[v3] Mode 'r+' is not working
5 participants