From f348b4d2b7e2f020d1fd152fc0a9467d300d5768 Mon Sep 17 00:00:00 2001 From: Matt Savoie Date: Thu, 18 Jan 2024 13:53:51 -0700 Subject: [PATCH 1/3] 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. --- docs/source/hierarchical-data.rst | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/source/hierarchical-data.rst b/docs/source/hierarchical-data.rst index 3cae4e3b..a58ccf4e 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 @@ -443,6 +424,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 From d2c569df98dbae1d4011d91cf81dca5051edb94c Mon Sep 17 00:00:00 2001 From: Matt Savoie Date: Thu, 18 Jan 2024 13:55:03 -0700 Subject: [PATCH 2/3] Show result of datatree.match operation for clarity. --- docs/source/hierarchical-data.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/hierarchical-data.rst b/docs/source/hierarchical-data.rst index a58ccf4e..91c3c90e 100644 --- a/docs/source/hierarchical-data.rst +++ b/docs/source/hierarchical-data.rst @@ -393,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. From 17846042cd52fa03cfdc1e09d0632e0b7caf4a05 Mon Sep 17 00:00:00 2001 From: Matt Savoie Date: Thu, 18 Jan 2024 13:55:22 -0700 Subject: [PATCH 3/3] fix typo wo => two --- docs/source/hierarchical-data.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/hierarchical-data.rst b/docs/source/hierarchical-data.rst index 91c3c90e..d4f58847 100644 --- a/docs/source/hierarchical-data.rst +++ b/docs/source/hierarchical-data.rst @@ -600,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