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

Commit 03b0a8c

Browse files
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 <[email protected]>
1 parent 14d6b6d commit 03b0a8c

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

docs/source/hierarchical-data.rst

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -369,25 +369,6 @@ You can see this tree is similar to the ``dt`` object above, except that it is m
369369

370370
(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)``.)
371371

372-
.. _Tree Contents:
373-
374-
Tree Contents
375-
-------------
376-
377-
Hollow Trees
378-
~~~~~~~~~~~~
379-
380-
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.
381-
This is useful because certain useful tree manipulation operations only make sense for hollow trees.
382-
383-
You can check if a tree is a hollow tree by using the :py:meth:`~DataTree.is_hollow` property.
384-
We can see that the Simpson's family is not hollow because the data variable ``"age"`` is present at some nodes which
385-
have children (i.e. Abe and Homer).
386-
387-
.. ipython:: python
388-
389-
simpsons.is_hollow
390-
391372
.. _manipulating trees:
392373

393374
Manipulating Trees
@@ -412,6 +393,7 @@ We can use :py:meth:`DataTree.match` for this:
412393
}
413394
)
414395
result = dt.match("*/B")
396+
result
415397
416398
We can also subset trees by the contents of the nodes.
417399
: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.
443425

444426
(Yes, under the hood :py:meth:`~DataTree.filter` is just syntactic sugar for the pattern we showed you in :ref:`iterating over trees` !)
445427

428+
.. _Tree Contents:
429+
430+
Tree Contents
431+
-------------
432+
433+
Hollow Trees
434+
~~~~~~~~~~~~
435+
436+
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.
437+
This is useful because certain useful tree manipulation operations only make sense for hollow trees.
438+
439+
You can check if a tree is a hollow tree by using the :py:class:`~DataTree.is_hollow` property.
440+
We can see that the Simpson's family is not hollow because the data variable ``"age"`` is present at some nodes which
441+
have children (i.e. Abe and Homer).
442+
443+
.. ipython:: python
444+
445+
simpsons.is_hollow
446+
446447
.. _tree computation:
447448

448449
Computation
@@ -599,7 +600,7 @@ Notice that corresponding tree nodes do not need to have the same name or contai
599600
Arithmetic Between Multiple Trees
600601
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
601602

602-
Arithmetic operations like multiplication are binary operations, so as long as we have wo isomorphic trees,
603+
Arithmetic operations like multiplication are binary operations, so as long as we have two isomorphic trees,
603604
we can do arithmetic between them.
604605

605606
.. ipython:: python

0 commit comments

Comments
 (0)