@@ -216,16 +216,16 @@ def test_is_hollow(self):
216
216
217
217
218
218
class TestToDataset :
219
- def test_to_dataset (self ):
220
- base = xr .Dataset (coords = {"a" : 1 })
221
- sub = xr .Dataset (coords = {"b " : 2 })
219
+ def test_to_dataset_inherited (self ):
220
+ base = xr .Dataset (coords = {"a" : [ 1 ], "b" : 2 })
221
+ sub = xr .Dataset (coords = {"c " : [ 3 ] })
222
222
tree = DataTree .from_dict ({"/" : base , "/sub" : sub })
223
223
subtree = typing .cast (DataTree , tree ["sub" ])
224
224
225
225
assert_identical (tree .to_dataset (inherited = False ), base )
226
226
assert_identical (subtree .to_dataset (inherited = False ), sub )
227
227
228
- sub_and_base = xr .Dataset (coords = {"a" : 1 , "b " : 2 })
228
+ sub_and_base = xr .Dataset (coords = {"a" : [ 1 ] , "c " : [ 3 ]}) # no "b"
229
229
assert_identical (tree .to_dataset (inherited = True ), base )
230
230
assert_identical (subtree .to_dataset (inherited = True ), sub_and_base )
231
231
@@ -714,7 +714,8 @@ def test_inherited(self):
714
714
dt ["child" ] = DataTree ()
715
715
child = dt ["child" ]
716
716
717
- assert set (child .coords ) == {"x" , "y" , "a" , "b" }
717
+ assert set (dt .coords ) == {"x" , "y" , "a" , "b" }
718
+ assert set (child .coords ) == {"x" , "y" }
718
719
719
720
actual = child .copy (deep = True )
720
721
actual .coords ["x" ] = ("x" , ["a" , "b" ])
@@ -729,7 +730,7 @@ def test_inherited(self):
729
730
730
731
with pytest .raises (KeyError ):
731
732
# cannot delete inherited coordinate from child node
732
- del child ["b " ]
733
+ del child ["x " ]
733
734
734
735
# TODO requires a fix for #9472
735
736
# actual = child.copy(deep=True)
@@ -1278,22 +1279,23 @@ def test_inherited_coords_index(self):
1278
1279
assert "x" in dt ["/b" ].coords
1279
1280
xr .testing .assert_identical (dt ["/x" ], dt ["/b/x" ])
1280
1281
1281
- def test_inherited_coords_override (self ):
1282
+ def test_inherit_only_index_coords (self ):
1282
1283
dt = DataTree .from_dict (
1283
1284
{
1284
- "/" : xr .Dataset (coords = {"x" : 1 , "y" : 2 }),
1285
- "/b" : xr .Dataset (coords = {"x" : 4 , " z" : 3 }),
1285
+ "/" : xr .Dataset (coords = {"x" : [ 1 ] , "y" : 2 }),
1286
+ "/b" : xr .Dataset (coords = {"z" : 3 }),
1286
1287
}
1287
1288
)
1288
1289
assert dt .coords .keys () == {"x" , "y" }
1289
- root_coords = {"x" : 1 , "y" : 2 }
1290
- sub_coords = {"x" : 4 , "y" : 2 , "z" : 3 }
1291
- xr .testing .assert_equal (dt ["/x" ], xr .DataArray (1 , coords = root_coords ))
1292
- xr .testing .assert_equal (dt ["/y" ], xr .DataArray (2 , coords = root_coords ))
1293
- assert dt ["/b" ].coords .keys () == {"x" , "y" , "z" }
1294
- xr .testing .assert_equal (dt ["/b/x" ], xr .DataArray (4 , coords = sub_coords ))
1295
- xr .testing .assert_equal (dt ["/b/y" ], xr .DataArray (2 , coords = sub_coords ))
1296
- xr .testing .assert_equal (dt ["/b/z" ], xr .DataArray (3 , coords = sub_coords ))
1290
+ xr .testing .assert_equal (
1291
+ dt ["/x" ], xr .DataArray ([1 ], dims = ["x" ], coords = {"x" : [1 ], "y" : 2 })
1292
+ )
1293
+ xr .testing .assert_equal (dt ["/y" ], xr .DataArray (2 , coords = {"y" : 2 }))
1294
+ assert dt ["/b" ].coords .keys () == {"x" , "z" }
1295
+ xr .testing .assert_equal (
1296
+ dt ["/b/x" ], xr .DataArray ([1 ], dims = ["x" ], coords = {"x" : [1 ], "z" : 3 })
1297
+ )
1298
+ xr .testing .assert_equal (dt ["/b/z" ], xr .DataArray (3 , coords = {"z" : 3 }))
1297
1299
1298
1300
def test_inherited_coords_with_index_are_deduplicated (self ):
1299
1301
dt = DataTree .from_dict (
0 commit comments