-
-
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
add enter and exit methods to groups. #2691
base: main
Are you sure you want to change the base?
Conversation
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.
Will you also add this for arrays?
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 for picking this up! Let's also get some unit tests for this. It will be important that we exercise this across all stores and establish expectations about behavior after the store has been closed.
src/zarr/core/group.py
Outdated
def __enter__(self) -> Self: | ||
return self | ||
|
||
def __exit__(self) -> None: # noqa: PYI036 |
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.
def __exit__(self) -> None: # noqa: PYI036 | |
def __exit__( | |
self, | |
typ: type[BaseException] | None, | |
exc: BaseException | None, | |
tb: TracebackType | None | |
) -> None: |
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.
updated in d8f7d68. Also added tests.
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.
Super close. A few suggestions on how to make the tests just a bit better.
|
||
# attempt to open a group that does not exist. | ||
with pytest.raises(FileNotFoundError): | ||
with Group.open(store) as store: |
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.
with Group.open(store) as store: | |
with Group.open(store) as g: |
assert group.store_path == spath | ||
|
||
# Check if store was closed after exit. | ||
assert not store._is_open |
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.
rather than using this private store api, let's try to just to use the group again and make sure it fails.
assert not store._is_open | |
with pytest.raises(ValueError): | |
group.attrs['path'] = 'bar' |
|
||
# attempt to open a group that does not exist. | ||
with pytest.raises(FileNotFoundError): | ||
with Group.open(store) as store: |
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.
also, instead of using Group.open
and Group.from_store
, can we use zarr.open_group
and zarr.create_group
? These are the public facing API methods we want most folks to be using.
Fixes: #2619
TODO: