From 03b0a8c04248ae2bb13ab8c4b832a9f406e0d156 Mon Sep 17 00:00:00 2001 From: Matt Savoie Date: Fri, 19 Jan 2024 15:52:51 -0700 Subject: [PATCH] Moves Tree Contents so that simpsons data tree in example is defined. (#301) * Moves Tree Contents so that simpsons data tree in example is defined. Also changes :py:meth => :py:class since it's a property not a method. * Show result of datatree.match operation for clarity. * fix typo wo => two --------- Co-authored-by: Tom Nicholas --- docs/source/hierarchical-data.rst | 41 ++++++++++++++++--------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/source/hierarchical-data.rst b/docs/source/hierarchical-data.rst index 3cae4e3b..d4f58847 100644 --- a/docs/source/hierarchical-data.rst +++ b/docs/source/hierarchical-data.rst @@ -369,25 +369,6 @@ You can see this tree is similar to the ``dt`` object above, except that it is m (If you want to keep the name of the root node, you will need to add the ``name`` kwarg to :py:class:`from_dict`, i.e. ``DataTree.from_dict(non_empty_nodes, name=dt.root.name)``.) -.. _Tree Contents: - -Tree Contents -------------- - -Hollow Trees -~~~~~~~~~~~~ - -A concept that can sometimes be useful is that of a "Hollow Tree", which means a tree with data stored only at the leaf nodes. -This is useful because certain useful tree manipulation operations only make sense for hollow trees. - -You can check if a tree is a hollow tree by using the :py:meth:`~DataTree.is_hollow` property. -We can see that the Simpson's family is not hollow because the data variable ``"age"`` is present at some nodes which -have children (i.e. Abe and Homer). - -.. ipython:: python - - simpsons.is_hollow - .. _manipulating trees: Manipulating Trees @@ -412,6 +393,7 @@ We can use :py:meth:`DataTree.match` for this: } ) result = dt.match("*/B") + result We can also subset trees by the contents of the nodes. :py:meth:`DataTree.filter` retains only the nodes of a tree that meet a certain condition. @@ -443,6 +425,25 @@ The result is a new tree, containing only the nodes matching the condition. (Yes, under the hood :py:meth:`~DataTree.filter` is just syntactic sugar for the pattern we showed you in :ref:`iterating over trees` !) +.. _Tree Contents: + +Tree Contents +------------- + +Hollow Trees +~~~~~~~~~~~~ + +A concept that can sometimes be useful is that of a "Hollow Tree", which means a tree with data stored only at the leaf nodes. +This is useful because certain useful tree manipulation operations only make sense for hollow trees. + +You can check if a tree is a hollow tree by using the :py:class:`~DataTree.is_hollow` property. +We can see that the Simpson's family is not hollow because the data variable ``"age"`` is present at some nodes which +have children (i.e. Abe and Homer). + +.. ipython:: python + + simpsons.is_hollow + .. _tree computation: Computation @@ -599,7 +600,7 @@ Notice that corresponding tree nodes do not need to have the same name or contai Arithmetic Between Multiple Trees ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Arithmetic operations like multiplication are binary operations, so as long as we have wo isomorphic trees, +Arithmetic operations like multiplication are binary operations, so as long as we have two isomorphic trees, we can do arithmetic between them. .. ipython:: python