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

datatree: Automatically close files using open_datatree context manager #9337

Closed
owenlittlejohns opened this issue Aug 13, 2024 · 0 comments · Fixed by #9651
Closed

datatree: Automatically close files using open_datatree context manager #9337

owenlittlejohns opened this issue Aug 13, 2024 · 0 comments · Fixed by #9651
Labels
needs triage Issue that has not been reviewed by xarray team member topic-DataTree Related to the implementation of a DataTree class

Comments

@owenlittlejohns
Copy link
Contributor

owenlittlejohns commented Aug 13, 2024

What is your issue?

Originally posted by @TomNicholas in xarray-contrib/datatree#93

Attempted implementation in this PR.

In xarray it's possible to automatically close a dataset after opening by opening it using a context manager. From the documentation:

# this automatically closes the dataset after use
In [5]: with xr.open_dataset("saved_on_disk.nc") as ds:
   ...:     print(ds.keys())
   ...: 

We currently don't have a DataTree.close() method, or any context manager behaviour for open_datatree. To add them presumably we would need to iterate over all file handles (i.e. groups) and close them one by one.

Related to xarray-contrib/datatree#90 @jhamman @thewtex

@owenlittlejohns owenlittlejohns added the needs triage Issue that has not been reviewed by xarray team member label Aug 13, 2024
@owenlittlejohns owenlittlejohns added the topic-DataTree Related to the implementation of a DataTree class label Aug 13, 2024
@keewis keewis changed the title Automatically close files using open_datatree context manager datatree: Automatically close files using open_datatree context manager Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue that has not been reviewed by xarray team member topic-DataTree Related to the implementation of a DataTree class
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant