Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Moves Tree Contents so that simpsons data tree in example is defined. (
Browse files Browse the repository at this point in the history
…#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 <tom@cworthy.org>
  • Loading branch information
flamingbear and TomNicholas authored Jan 19, 2024
1 parent 14d6b6d commit 03b0a8c
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions docs/source/hierarchical-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 03b0a8c

Please sign in to comment.