Skip to content

Commit a6a06b2

Browse files
author
Kay Jan
authored
Merge pull request #70 from kayjan/v0.10.0
V0.10.0
2 parents bab6b17 + 702a31c commit a6a06b2

File tree

11 files changed

+728
-171
lines changed

11 files changed

+728
-171
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.10.0] - 2023-07-15
8+
### Added
9+
- [#65] Tree Search: Implement `find_relative_path` to find relative path from node.
10+
- [#65] Utility Iterator: Implement `zigzag_iter` and `zigzaggroup_iter` Tree traversal methods.
11+
712
## [0.9.5] - 2023-07-13
813
### Added
914
- Misc: Added init files, add link to discussions to README and pyproject, add sphinx coverage shortcuts.
@@ -284,6 +289,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
284289
- Utility Iterator: Tree traversal methods.
285290
- Workflow To Do App: Tree use case with to-do list implementation.
286291

292+
[0.10.0]: https://github.com/kayjan/bigtree/compare/0.9.5...0.10.0
287293
[0.9.5]: https://github.com/kayjan/bigtree/compare/0.9.4...0.9.5
288294
[0.9.4]: https://github.com/kayjan/bigtree/compare/0.9.3...0.9.4
289295
[0.9.3]: https://github.com/kayjan/bigtree/compare/0.9.2...0.9.3

bigtree/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.9.5"
1+
__version__ = "0.10.0"
22

33
from bigtree.binarytree.construct import list_to_binarytree
44
from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag
@@ -49,6 +49,7 @@
4949
find_names,
5050
find_path,
5151
find_paths,
52+
find_relative_path,
5253
findall,
5354
)
5455
from bigtree.utils.exceptions import (
@@ -66,6 +67,8 @@
6667
levelordergroup_iter,
6768
postorder_iter,
6869
preorder_iter,
70+
zigzag_iter,
71+
zigzaggroup_iter,
6972
)
7073
from bigtree.workflows.app_calendar import Calendar
7174
from bigtree.workflows.app_todo import AppToDo

bigtree/binarytree/construct.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ def list_to_binarytree(
1010
) -> BinaryNode:
1111
"""Construct tree from list of numbers (int or float) in heapq format.
1212
13-
>>> from bigtree import list_to_binarytree, print_tree, tree_to_dot
13+
>>> from bigtree import list_to_binarytree, tree_to_dot
1414
>>> nums_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1515
>>> root = list_to_binarytree(nums_list)
16-
>>> print_tree(root)
16+
>>> root.show()
1717
1
1818
├── 2
1919
│ ├── 4

bigtree/tree/construct.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def add_path_to_tree(
4545
All paths should start from the same root node.
4646
- For example: Path strings should be "a/b", "a/c", "a/b/d" etc. and should not start with another root node.
4747
48-
>>> from bigtree import add_path_to_tree, print_tree
48+
>>> from bigtree import add_path_to_tree
4949
>>> root = Node("a")
5050
>>> add_path_to_tree(root, "a/b/c")
5151
Node(/a/b/c, )
52-
>>> print_tree(root)
52+
>>> root.show()
5353
a
5454
└── b
5555
└── c
@@ -119,7 +119,7 @@ def add_dict_to_tree_by_path(
119119
All paths should start from the same root node.
120120
- For example: Path strings should be "a/b", "a/c", "a/b/d" etc. and should not start with another root node.
121121
122-
>>> from bigtree import Node, add_dict_to_tree_by_path, print_tree
122+
>>> from bigtree import Node, add_dict_to_tree_by_path
123123
>>> root = Node("a")
124124
>>> path_dict = {
125125
... "a": {"age": 90},
@@ -132,7 +132,7 @@ def add_dict_to_tree_by_path(
132132
... "a/b/e/h": {"age": 6},
133133
... }
134134
>>> root = add_dict_to_tree_by_path(root, path_dict)
135-
>>> print_tree(root)
135+
>>> root.show()
136136
a
137137
├── b
138138
│ ├── d
@@ -178,15 +178,15 @@ def add_dict_to_tree_by_name(
178178
Input dictionary keys that are not existing node names will be ignored.
179179
Note that if multiple nodes have the same name, attributes will be added to all nodes sharing same name.
180180
181-
>>> from bigtree import Node, add_dict_to_tree_by_name, print_tree
181+
>>> from bigtree import Node, add_dict_to_tree_by_name
182182
>>> root = Node("a")
183183
>>> b = Node("b", parent=root)
184184
>>> name_dict = {
185185
... "a": {"age": 90},
186186
... "b": {"age": 65},
187187
... }
188188
>>> root = add_dict_to_tree_by_name(root, name_dict)
189-
>>> print_tree(root, attr_list=["age"])
189+
>>> root.show(attr_list=["age"])
190190
a [age=90]
191191
└── b [age=65]
192192
@@ -235,7 +235,7 @@ def add_dataframe_to_tree_by_path(
235235
- For example: Path strings should be "a/b", "a/c", "a/b/d" etc. and should not start with another root node.
236236
237237
>>> import pandas as pd
238-
>>> from bigtree import add_dataframe_to_tree_by_path, print_tree
238+
>>> from bigtree import add_dataframe_to_tree_by_path
239239
>>> root = Node("a")
240240
>>> path_data = pd.DataFrame([
241241
... ["a", 90],
@@ -250,7 +250,7 @@ def add_dataframe_to_tree_by_path(
250250
... columns=["PATH", "age"]
251251
... )
252252
>>> root = add_dataframe_to_tree_by_path(root, path_data)
253-
>>> print_tree(root, attr_list=["age"])
253+
>>> root.show(attr_list=["age"])
254254
a [age=90]
255255
├── b [age=65]
256256
│ ├── d [age=40]
@@ -333,7 +333,7 @@ def add_dataframe_to_tree_by_name(
333333
Note that if multiple nodes have the same name, attributes will be added to all nodes sharing same name.
334334
335335
>>> import pandas as pd
336-
>>> from bigtree import add_dataframe_to_tree_by_name, print_tree
336+
>>> from bigtree import add_dataframe_to_tree_by_name
337337
>>> root = Node("a")
338338
>>> b = Node("b", parent=root)
339339
>>> name_data = pd.DataFrame([
@@ -343,7 +343,7 @@ def add_dataframe_to_tree_by_name(
343343
... columns=["NAME", "age"]
344344
... )
345345
>>> root = add_dataframe_to_tree_by_name(root, name_data)
346-
>>> print_tree(root, attr_list=["age"])
346+
>>> root.show(attr_list=["age"])
347347
a [age=90]
348348
└── b [age=65]
349349
@@ -418,10 +418,10 @@ def str_to_tree(
418418
) -> Node:
419419
r"""Construct tree from tree string
420420
421-
>>> from bigtree import str_to_tree, print_tree
421+
>>> from bigtree import str_to_tree
422422
>>> tree_str = 'a\n├── b\n│ ├── d\n│ └── e\n│ ├── g\n│ └── h\n└── c\n └── f'
423423
>>> root = str_to_tree(tree_str, tree_prefix_list=["├──", "└──"])
424-
>>> print_tree(root)
424+
>>> root.show()
425425
a
426426
├── b
427427
│ ├── d
@@ -496,10 +496,10 @@ def list_to_tree(
496496
All paths should start from the same root node.
497497
- For example: Path strings should be "a/b", "a/c", "a/b/d" etc. and should not start with another root node.
498498
499-
>>> from bigtree import list_to_tree, print_tree
499+
>>> from bigtree import list_to_tree
500500
>>> path_list = ["a/b", "a/c", "a/b/d", "a/b/e", "a/c/f", "a/b/e/g", "a/b/e/h"]
501501
>>> root = list_to_tree(path_list)
502-
>>> print_tree(root)
502+
>>> root.show()
503503
a
504504
├── b
505505
│ ├── d
@@ -548,10 +548,10 @@ def list_to_tree_by_relation(
548548
Error will be thrown if names of intermediate nodes are repeated as there will be confusion.
549549
This error can be ignored by setting `allow_duplicates` to be True.
550550
551-
>>> from bigtree import list_to_tree_by_relation, print_tree
551+
>>> from bigtree import list_to_tree_by_relation
552552
>>> relations_list = [("a", "b"), ("a", "c"), ("b", "d"), ("b", "e"), ("c", "f"), ("e", "g"), ("e", "h")]
553553
>>> root = list_to_tree_by_relation(relations_list)
554-
>>> print_tree(root)
554+
>>> root.show()
555555
a
556556
├── b
557557
│ ├── d
@@ -601,7 +601,7 @@ def dict_to_tree(
601601
All paths should start from the same root node.
602602
- For example: Path strings should be "a/b", "a/c", "a/b/d" etc. and should not start with another root node.
603603
604-
>>> from bigtree import dict_to_tree, print_tree
604+
>>> from bigtree import dict_to_tree
605605
>>> path_dict = {
606606
... "a": {"age": 90},
607607
... "a/b": {"age": 65},
@@ -613,7 +613,7 @@ def dict_to_tree(
613613
... "a/b/e/h": {"age": 6},
614614
... }
615615
>>> root = dict_to_tree(path_dict)
616-
>>> print_tree(root, attr_list=["age"])
616+
>>> root.show(attr_list=["age"])
617617
a [age=90]
618618
├── b [age=65]
619619
│ ├── d [age=40]
@@ -657,7 +657,7 @@ def nested_dict_to_tree(
657657
- ``value`` of `name_key` (str): node name.
658658
- ``value`` of `child_key` (List[Dict[str, Any]]): list of dict containing `name_key` and `child_key` (recursive).
659659
660-
>>> from bigtree import nested_dict_to_tree, print_tree
660+
>>> from bigtree import nested_dict_to_tree
661661
>>> path_dict = {
662662
... "name": "a",
663663
... "age": 90,
@@ -673,7 +673,7 @@ def nested_dict_to_tree(
673673
... ],
674674
... }
675675
>>> root = nested_dict_to_tree(path_dict)
676-
>>> print_tree(root, attr_list=["age"])
676+
>>> root.show(attr_list=["age"])
677677
a [age=90]
678678
└── b [age=65]
679679
├── d [age=40]
@@ -733,7 +733,7 @@ def dataframe_to_tree(
733733
- For example: Path strings should be "a/b", "a/c", "a/b/d" etc. and should not start with another root node.
734734
735735
>>> import pandas as pd
736-
>>> from bigtree import dataframe_to_tree, print_tree
736+
>>> from bigtree import dataframe_to_tree
737737
>>> path_data = pd.DataFrame([
738738
... ["a", 90],
739739
... ["a/b", 65],
@@ -747,7 +747,7 @@ def dataframe_to_tree(
747747
... columns=["PATH", "age"]
748748
... )
749749
>>> root = dataframe_to_tree(path_data)
750-
>>> print_tree(root, attr_list=["age"])
750+
>>> root.show(attr_list=["age"])
751751
a [age=90]
752752
├── b [age=65]
753753
│ ├── d [age=40]
@@ -832,7 +832,7 @@ def dataframe_to_tree_by_relation(
832832
columns are `attribute_cols`.
833833
834834
>>> import pandas as pd
835-
>>> from bigtree import dataframe_to_tree_by_relation, print_tree
835+
>>> from bigtree import dataframe_to_tree_by_relation
836836
>>> relation_data = pd.DataFrame([
837837
... ["a", None, 90],
838838
... ["b", "a", 65],
@@ -846,7 +846,7 @@ def dataframe_to_tree_by_relation(
846846
... columns=["child", "parent", "age"]
847847
... )
848848
>>> root = dataframe_to_tree_by_relation(relation_data)
849-
>>> print_tree(root, attr_list=["age"])
849+
>>> root.show(attr_list=["age"])
850850
a [age=90]
851851
├── b [age=65]
852852
│ ├── d [age=40]

bigtree/tree/helper.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ def prune_tree(
6060
Path should contain `Node` name, separated by `sep`.
6161
- For example: Path string "a/b" refers to Node("b") with parent Node("a").
6262
63-
>>> from bigtree import Node, prune_tree, print_tree
63+
>>> from bigtree import Node, prune_tree
6464
>>> root = Node("a")
6565
>>> b = Node("b", parent=root)
6666
>>> c = Node("c", parent=root)
67-
>>> print_tree(root)
67+
>>> root.show()
6868
a
6969
├── b
7070
└── c
7171
7272
>>> root_pruned = prune_tree(root, "a/b")
73-
>>> print_tree(root_pruned)
73+
>>> root_pruned.show()
7474
a
7575
└── b
7676
@@ -113,13 +113,13 @@ def get_tree_diff(tree: Node, other_tree: Node, only_diff: bool = True) -> Node:
113113
114114
Function can return all original tree nodes and differences, or only the differences.
115115
116-
>>> from bigtree import Node, get_tree_diff, print_tree
116+
>>> from bigtree import Node, get_tree_diff
117117
>>> root = Node("a")
118118
>>> b = Node("b", parent=root)
119119
>>> c = Node("c", parent=root)
120120
>>> d = Node("d", parent=b)
121121
>>> e = Node("e", parent=root)
122-
>>> print_tree(root)
122+
>>> root.show()
123123
a
124124
├── b
125125
│ └── d
@@ -131,15 +131,15 @@ def get_tree_diff(tree: Node, other_tree: Node, only_diff: bool = True) -> Node:
131131
>>> c_other = Node("c", parent=b_other)
132132
>>> d_other = Node("d", parent=root_other)
133133
>>> e_other = Node("e", parent=root_other)
134-
>>> print_tree(root_other)
134+
>>> root_other.show()
135135
a
136136
├── b
137137
│ └── c
138138
├── d
139139
└── e
140140
141141
>>> tree_diff = get_tree_diff(root, root_other)
142-
>>> print_tree(tree_diff)
142+
>>> tree_diff.show()
143143
a
144144
├── b
145145
│ ├── c (+)
@@ -148,7 +148,7 @@ def get_tree_diff(tree: Node, other_tree: Node, only_diff: bool = True) -> Node:
148148
└── d (+)
149149
150150
>>> tree_diff = get_tree_diff(root, root_other, only_diff=False)
151-
>>> print_tree(tree_diff)
151+
>>> tree_diff.show()
152152
a
153153
├── b
154154
│ ├── c (+)

0 commit comments

Comments
 (0)