Skip to content

Commit

Permalink
Add test that shows that we need an unstructure_hook for DataTree
Browse files Browse the repository at this point in the history
This is the simplest way to keep DataTree object the original.
Otherwise it would return a copy of some sort.
  • Loading branch information
deltamarnix committed Dec 13, 2024
1 parent fb44fe6 commit fa21d42
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/test_cattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,19 @@ def test_unstructure_xarray_tree_to_ascii():
# The whole string will be in memory when doing this,
# duplicating the data.
assert f_dict == "1 2 3"


def test_unstructure_xarray_tree():
x_arr = xr.DataArray([1, 2, 3])
x_set = xr.Dataset({"x": x_arr})
x_tree = xr.DataTree(x_set)
f = Baz(x=x_tree)

converter = Converter()
converter.register_unstructure_hook(xr.DataTree, lambda v: v)
f_dict = converter.unstructure(f)

# We expect that the default unstructure functionality keeps
# the xarray as is.
# This helps when finally converting the dictionary to MF6 input files.
assert x_tree is f_dict["x"]

0 comments on commit fa21d42

Please sign in to comment.