Skip to content

Commit

Permalink
add testcase that allows non-inherited (duplicated names and differen…
Browse files Browse the repository at this point in the history
…t values/shapes) vars, coords and dims
  • Loading branch information
acrosby committed Jul 13, 2024
1 parent 97e971e commit 1e16ffb
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion xarray/tests/test_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,68 @@ def test_inconsistent_grandchild_dims(self):
with pytest.raises(ValueError, match=expected_msg):
dt["/b/c/d"] = xr.DataArray([3.0], dims=["x"])

def test_allow_inconsistent_noninherited_coords_dims_vars(
self, create_test_multidataset_withoutroot_datatree
):
dt_fd = DataTree.from_dict(
{
"/Main": xr.Dataset(
{
"x": (
["yi", "xi"],
np.meshgrid(np.arange(60), np.arange(50))[1],
),
"y": (
["yi", "xi"],
np.meshgrid(np.arange(60), np.arange(50))[0],
),
"t": ("t", np.arange(30)),
"u": (["t", "yi", "xi"], np.zeros((30, 50, 60))),
"v": (["t", "yi", "xi"], np.zeros((30, 50, 60))),
"p": (["t", "yi", "xi"], np.zeros((30, 50, 60))),
}
),
"/ovr1": xr.Dataset(
{
"x": (
["yi", "xi"],
np.meshgrid(np.arange(51), np.arange(51) + 150.0)[1],
),
"y": (
["yi", "xi"],
np.meshgrid(np.arange(51), np.arange(51))[0],
),
"t": ("t", np.arange(10, 20)),
"u": (["t", "yi", "xi"], np.zeros((10, 51, 51))),
"v": (["t", "yi", "xi"], np.zeros((10, 51, 51))),
"p": (["t", "yi", "xi"], np.zeros((10, 51, 51))),
"cx": ("t", np.arange(10, 20)),
"cy": ("t", np.arange(10, 20)),
}
),
"/ovr2": xr.Dataset(
{
"x": (
["yi", "xi"],
np.meshgrid(np.arange(51), np.arange(51))[1],
),
"y": (
["yi", "xi"],
np.meshgrid(np.arange(51), np.arange(51))[0],
),
"t": ("t", np.arange(10, 30)),
"u": (["t", "yi", "xi"], np.zeros((20, 51, 51))),
"v": (["t", "yi", "xi"], np.zeros((20, 51, 51))),
"p": (["t", "yi", "xi"], np.zeros((20, 51, 51))),
"cx": ("t", np.arange(10, 30)),
"cy": ("t", np.arange(10, 30)),
}
),
}
)
dt = create_test_multidataset_withoutroot_datatree()
assert_equal(dt, dt_fd)


class TestRestructuring:
def test_drop_nodes(self):
Expand Down Expand Up @@ -1123,7 +1185,6 @@ class TestDocInsertion:
"""Tests map_over_subtree docstring injection."""

def test_standard_doc(self):

dataset_doc = dedent(
"""\
Manually trigger loading and/or computation of this dataset's data
Expand Down

0 comments on commit 1e16ffb

Please sign in to comment.