diff --git a/xarray/core/datatree.py b/xarray/core/datatree.py index 65ff8667cb7..b73e1a84a21 100644 --- a/xarray/core/datatree.py +++ b/xarray/core/datatree.py @@ -1104,7 +1104,8 @@ def from_dict( if d: # Populate tree with children determined from data_objects mapping - for path, data in d.items(): + # Sort keys so as to insert nodes from root first (see GH issue #9276) + for path, data in sorted(d.items()): # Create and set new node node_name = NodePath(path).name if isinstance(data, DataTree):