Skip to content

Commit 33bb781

Browse files
authored
Merge pull request #223 from kayjan/fix-error-dtype
fix: dataframe_to_tree_by_relation error message to handle different …
2 parents 411c7ea + 9f10b1f commit 33bb781

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.17.1] - 2024-04-23
10+
### Fixed
11+
- [#222] Tree Constructor: `dataframe_to_tree_by_relation` duplicate root node name error message to handle
12+
different data types.
13+
914
## [0.17.0] - 2024-04-04
1015
### Added
1116
- Misc: Group tests for benchmark timings to compare the timings by multiplier more effectively.
@@ -540,7 +545,8 @@ ignore null attribute columns.
540545
- Utility Iterator: Tree traversal methods.
541546
- Workflow To Do App: Tree use case with to-do list implementation.
542547

543-
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.17.0...HEAD
548+
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.17.1...HEAD
549+
[0.17.1]: https://github.com/kayjan/bigtree/compare/0.17.0...0.17.1
544550
[0.17.0]: https://github.com/kayjan/bigtree/compare/0.16.4...0.17.0
545551
[0.16.4]: https://github.com/kayjan/bigtree/compare/0.16.3...0.16.4
546552
[0.16.3]: https://github.com/kayjan/bigtree/compare/0.16.2...0.16.3

bigtree/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.17.0"
1+
__version__ = "0.17.1"
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

bigtree/tree/construct.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,8 @@ def dataframe_to_tree_by_relation(
944944
root_names.update(set(data[parent_col]) - set(data[child_col]) - {None})
945945
if len(root_names) != 1:
946946
raise ValueError(
947-
f"Unable to determine root node\nPossible root nodes: {sorted(root_names)}"
947+
f"Unable to determine root node\n"
948+
f"Possible root nodes: {sorted(list(root_names), key=lambda v: (isinstance(v, str), v))}"
948949
)
949950
root_name = list(root_names)[0]
950951

tests/tree/test_construct.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,26 @@ def test_dataframe_to_tree_by_relation_multiple_root_error():
26642664
exc_info.value
26652665
) == Constants.ERROR_NODE_DATAFRAME_MULTIPLE_ROOT.format(root_nodes=["a", "b"])
26662666

2667+
@staticmethod
2668+
def test_dataframe_to_tree_by_relation_multiple_root_and_type_error():
2669+
relation_data = pd.DataFrame(
2670+
[
2671+
["a", None, 90],
2672+
["c", "a", 60],
2673+
["d", 1, 40],
2674+
["e", 1, 35],
2675+
["f", "c", 38],
2676+
["g", "e", 10],
2677+
["h", "e", 6],
2678+
],
2679+
columns=["child", "parent", "age"],
2680+
)
2681+
with pytest.raises(ValueError) as exc_info:
2682+
dataframe_to_tree_by_relation(relation_data)
2683+
assert str(
2684+
exc_info.value
2685+
) == Constants.ERROR_NODE_DATAFRAME_MULTIPLE_ROOT.format(root_nodes=[1, "a"])
2686+
26672687
@staticmethod
26682688
def test_dataframe_to_tree_by_relation_no_root_error():
26692689
relation_data = pd.DataFrame(

0 commit comments

Comments
 (0)