MCPcopy Index your code
hub / github.com/pydata/xarray / test_drop_nodes

Method test_drop_nodes

xarray/tests/test_datatree.py:1755–1773  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1753
1754class TestRestructuring:
1755 def test_drop_nodes(self) -> None:
1756 sue = DataTree.from_dict({"Mary": None, "Kate": None, "Ashley": None})
1757
1758 # test drop just one node
1759 dropped_one = sue.drop_nodes(names="Mary")
1760 assert "Mary" not in dropped_one.children
1761
1762 # test drop multiple nodes
1763 dropped = sue.drop_nodes(names=["Mary", "Kate"])
1764 assert not {"Mary", "Kate"}.intersection(set(dropped.children))
1765 assert "Ashley" in dropped.children
1766
1767 # test raise
1768 with pytest.raises(KeyError, match=r"nodes {'Mary'} not present"):
1769 dropped.drop_nodes(names=["Mary", "Ashley"])
1770
1771 # test ignore
1772 childless = dropped.drop_nodes(names=["Mary", "Ashley"], errors="ignore")
1773 assert childless.children == {}
1774
1775 def test_assign(self) -> None:
1776 dt = DataTree()

Callers

nothing calls this directly

Calls 2

drop_nodesMethod · 0.80
from_dictMethod · 0.45

Tested by

no test coverage detected