Skip to content

Commit fa69ad7

Browse files
committed
don't need to special case root when saving to netcdf
1 parent 15e7b12 commit fa69ad7

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

datatree/io.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,7 @@ def _datatree_to_netcdf(
114114
if unlimited_dims is None:
115115
unlimited_dims = {}
116116

117-
ds = dt.ds
118-
group_path = dt.pathstr.replace(dt.root.pathstr, "")
119-
if ds is None:
120-
_create_empty_group(filepath, group_path, mode)
121-
else:
122-
ds.to_netcdf(
123-
filepath,
124-
group=group_path,
125-
mode=mode,
126-
encoding=_maybe_extract_group_kwargs(encoding, dt.pathstr),
127-
unlimited_dims=_maybe_extract_group_kwargs(unlimited_dims, dt.pathstr),
128-
**kwargs
129-
)
130-
mode = "a"
131-
132-
for node in dt.descendants:
117+
for node in dt.subtree:
133118
ds = node.ds
134119
group_path = node.pathstr.replace(dt.root.pathstr, "")
135120
if ds is None:
@@ -143,3 +128,4 @@ def _datatree_to_netcdf(
143128
unlimited_dims=_maybe_extract_group_kwargs(unlimited_dims, dt.pathstr),
144129
**kwargs
145130
)
131+
mode = "a"

0 commit comments

Comments
 (0)