Align datatree to_dict
and from_dict
to similar methods on Dataset
and DataArray
level
#9080
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
from_dict
andto_dict
behaviours to their Dataset equivalents #9074whats-new.rst
api.rst
to_native_dict
andfrom_native_dict
This Pull Request adds two new methods on the DataTree class:
to_native_dict
andfrom_native_dict
.~~The existing ones are renamed to
to_paths_dict
andfrom_paths_dict
, as their working data structure is a dict of paths to xarray data structures. ~~DataTree.from_dict
->DataTree.from_paths_dict
DataTree.to_dict
->DataTree.to_paths_dict
The goal is to convert back-and-forth DataTrees to Python dictionaries, with the final goal (left to the user) of dumping these dictionaries to JSON, and read back JSON to a DataTree. The motive is exposed in #9074
Open Points
(1)
Since theDataTree.to_dict
andDataTree.from_dict
already exist on DataTree, but with a different behaviour, this change is a breaking change. I think it is needed for having a behaviour similar on the existing Dataset methods.However, if the current usage offrom_dict
andto_dict
is already so widespread that it cannot be renamed easily, then an option can be added to thefrom_dict
andto_dict
methods to switch between the current behaviour (convert a mapping of str paths to xarray objets to a DataTree) and the new (convert to a recursive dict with no left xarray structure, delegating lower-lever conversion of datasets toDataset.to_dict
andDataset.from_dict