MCPcopy
hub / github.com/pydata/xarray / test_concat_multi_dim_index

Function test_concat_multi_dim_index

xarray/tests/test_concat.py:1594–1638  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1592
1593
1594def test_concat_multi_dim_index() -> None:
1595 ds1 = (
1596 Dataset(
1597 {"foo": (("x", "y"), np.random.randn(2, 2))},
1598 coords={"x": [1, 2], "y": [3, 4]},
1599 )
1600 .drop_indexes(["x", "y"])
1601 .set_xindex(["x", "y"], XYIndex)
1602 )
1603 ds2 = (
1604 Dataset(
1605 {"foo": (("x", "y"), np.random.randn(2, 2))},
1606 coords={"x": [1, 2], "y": [5, 6]},
1607 )
1608 .drop_indexes(["x", "y"])
1609 .set_xindex(["x", "y"], XYIndex)
1610 )
1611
1612 expected = (
1613 Dataset(
1614 {
1615 "foo": (
1616 ("x", "y"),
1617 np.concatenate([ds1.foo.data, ds2.foo.data], axis=-1),
1618 )
1619 },
1620 coords={"x": [1, 2], "y": [3, 4, 5, 6]},
1621 )
1622 .drop_indexes(["x", "y"])
1623 .set_xindex(["x", "y"], XYIndex)
1624 )
1625 # note: missing 'override'
1626 joins: list[types.JoinOptions] = ["inner", "outer", "exact", "left", "right"]
1627 for join in joins:
1628 actual = concat([ds1, ds2], dim="y", join=join)
1629 assert_identical(actual, expected, check_default_indexes=False)
1630
1631 with pytest.raises(AlignmentError):
1632 actual = concat([ds1, ds2], dim="x", join="exact")
1633
1634 # TODO: fix these, or raise better error message
1635 with pytest.raises(AssertionError):
1636 joins_lr: list[types.JoinOptions] = ["left", "right"]
1637 for join in joins_lr:
1638 actual = concat([ds1, ds2], dim="x", join=join)
1639
1640
1641class TestConcatDataTree:

Callers

nothing calls this directly

Calls 5

DatasetClass · 0.90
concatFunction · 0.90
assert_identicalFunction · 0.90
set_xindexMethod · 0.45
drop_indexesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…