Description
What is your issue?
DataTree.from_dict
supports DataTree
and Dataset
values.
It would be nice to also support DataArray
and Variable
objects with fully qualified paths. Similar to the Dataset
constructor, we would need a separate coords
argument.
I am thinking something like:
tree = DataTree.from_dict(
data_vars={'/a': a, '/child/b': b, '/child/grandchild/c': c},
coords={'/child/x': x},
)
where the values a
, b
, c
and x
are all DataArray objects (or anything supported in the Dataset constructor).
We could support this inside DataTree.from_dict
by adding a new coords
argument and renaming the first argument to data
, i.e.,
@classmethod
def from_dict(
cls,
data: Mapping[str, DataArrayLike | Dataset | DataTree | None] | None = None,
coords: Mapping[str, DataArrayLike] | None = None
name: str | None = None,
) -> DataTree:
where DataArrayLike
is an alias for everything valid in the Dataset constructor (DataArray | Variable | tuple | Numeric
).
We could also make a dedicated constructor for this, e.g., DataTree.from_array_dict
. If we took this approach, I would consider renaming the existing from_dict
constructor, e.g., to DataTree.from_dataset_dict
.
CC the usual DataTree crew: @TomNicholas @eni-awowale @flamingbear @owenlittlejohns