Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
don't need to special case root when saving to netcdf
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Aug 27, 2021
1 parent 649fe45 commit 37f5d30
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions datatree/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,7 @@ def _datatree_to_netcdf(
if unlimited_dims is None:
unlimited_dims = {}

ds = dt.ds
group_path = dt.pathstr.replace(dt.root.pathstr, "")
if ds is None:
_create_empty_group(filepath, group_path, mode)
else:
ds.to_netcdf(
filepath,
group=group_path,
mode=mode,
encoding=_maybe_extract_group_kwargs(encoding, dt.pathstr),
unlimited_dims=_maybe_extract_group_kwargs(unlimited_dims, dt.pathstr),
**kwargs
)
mode = "a"

for node in dt.descendants:
for node in dt.subtree:
ds = node.ds
group_path = node.pathstr.replace(dt.root.pathstr, "")
if ds is None:
Expand All @@ -143,3 +128,4 @@ def _datatree_to_netcdf(
unlimited_dims=_maybe_extract_group_kwargs(unlimited_dims, dt.pathstr),
**kwargs
)
mode = "a"

0 comments on commit 37f5d30

Please sign in to comment.