Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.1] - 2024-04-23
### Fixed
- [#222] Tree Constructor: `dataframe_to_tree_by_relation` duplicate root node name error message to handle
different data types.

## [0.17.0] - 2024-04-04
### Added
- Misc: Group tests for benchmark timings to compare the timings by multiplier more effectively.
Expand Down Expand Up @@ -540,7 +545,8 @@ ignore null attribute columns.
- Utility Iterator: Tree traversal methods.
- Workflow To Do App: Tree use case with to-do list implementation.

[Unreleased]: https://github.com/kayjan/bigtree/compare/0.17.0...HEAD
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.17.1...HEAD
[0.17.1]: https://github.com/kayjan/bigtree/compare/0.17.0...0.17.1
[0.17.0]: https://github.com/kayjan/bigtree/compare/0.16.4...0.17.0
[0.16.4]: https://github.com/kayjan/bigtree/compare/0.16.3...0.16.4
[0.16.3]: https://github.com/kayjan/bigtree/compare/0.16.2...0.16.3
Expand Down
2 changes: 1 addition & 1 deletion bigtree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.17.0"
__version__ = "0.17.1"

from bigtree.binarytree.construct import list_to_binarytree
from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag
Expand Down
3 changes: 2 additions & 1 deletion bigtree/tree/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,8 @@ def dataframe_to_tree_by_relation(
root_names.update(set(data[parent_col]) - set(data[child_col]) - {None})
if len(root_names) != 1:
raise ValueError(
f"Unable to determine root node\nPossible root nodes: {sorted(root_names)}"
f"Unable to determine root node\n"
f"Possible root nodes: {sorted(list(root_names), key=lambda v: (isinstance(v, str), v))}"
)
root_name = list(root_names)[0]

Expand Down
20 changes: 20 additions & 0 deletions tests/tree/test_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,26 @@ def test_dataframe_to_tree_by_relation_multiple_root_error():
exc_info.value
) == Constants.ERROR_NODE_DATAFRAME_MULTIPLE_ROOT.format(root_nodes=["a", "b"])

@staticmethod
def test_dataframe_to_tree_by_relation_multiple_root_and_type_error():
relation_data = pd.DataFrame(
[
["a", None, 90],
["c", "a", 60],
["d", 1, 40],
["e", 1, 35],
["f", "c", 38],
["g", "e", 10],
["h", "e", 6],
],
columns=["child", "parent", "age"],
)
with pytest.raises(ValueError) as exc_info:
dataframe_to_tree_by_relation(relation_data)
assert str(
exc_info.value
) == Constants.ERROR_NODE_DATAFRAME_MULTIPLE_ROOT.format(root_nodes=[1, "a"])

@staticmethod
def test_dataframe_to_tree_by_relation_no_root_error():
relation_data = pd.DataFrame(
Expand Down