Skip to content

datatree: Automatically close files using open_datatree context managerΒ #9337

@owenlittlejohns

Description

@owenlittlejohns

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageIssue that has not been reviewed by xarray team membertopic-DataTreeRelated to the implementation of a DataTree class

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions