Skip to content

Commit

Permalink
v0.4.4 handle null in array when adding list-like attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayjan committed Nov 8, 2022
1 parent 078858a commit 092f41e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Work In Progress
- Node: WeightedNode for weighted edge tree implementation.

## [0.4.4] - 2022-11-08
### Fixed
- Tree Constructors: Handle adding attributes that are array-like - add array even when one of the items is null

## [0.4.3] - 2022-11-08
### Added
- Node: Print format for BaseNode.
Expand Down Expand Up @@ -67,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Utility Iterators: Tree traversal methods.
- Workflow To Do App: Tree use case with to-do list implementation.

[0.4.3]: https://github.com/kayjan/bigtree/compare/v0.4.3...v0.4.4
[0.4.3]: https://github.com/kayjan/bigtree/compare/v0.4.2...v0.4.3
[0.4.2]: https://github.com/kayjan/bigtree/compare/v0.4.1...v0.4.2
[0.4.1]: https://github.com/kayjan/bigtree/compare/v0.4.0...v0.4.1
Expand Down
2 changes: 1 addition & 1 deletion bigtree/tree/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def add_dataframe_to_tree_by_path(
for row in data.to_dict(orient="index").values():
node_attrs = row.copy()
del node_attrs[path_col]
node_attrs = {k: v for k, v in node_attrs.items() if not np.any(pd.isnull(v))}
node_attrs = {k: v for k, v in node_attrs.items() if not np.all(pd.isnull(v))}
add_path_to_tree(
tree_root,
row[path_col],
Expand Down
6 changes: 6 additions & 0 deletions docs/source/bigtree/node/dagnode.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DAGNode
=====================

.. automodule:: bigtree.node.dagnode
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/node.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Node

bigtree/node/basenode
bigtree/node/node
bigtree/node/dagnode
20 changes: 19 additions & 1 deletion tests/tree/test_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pandas as pd
import pytest

from bigtree import find_names
from bigtree.node.node import Node
from bigtree.tree.construct import (
add_dataframe_to_tree_by_name,
Expand All @@ -17,6 +16,7 @@
list_to_tree_tuples,
nested_dict_to_tree,
)
from bigtree.tree.search import find_name, find_names
from bigtree.utils.exceptions import DuplicatedNodeError, TreeError
from tests.node.test_basenode import (
assert_tree_structure_basenode_root_attr,
Expand Down Expand Up @@ -362,6 +362,24 @@ def test_add_dict_to_tree_by_name(self):
assert_tree_structure_basenode_root_attr(root)
assert_tree_structure_node_root_generic(root)

def test_add_dict_to_tree_by_name_different_dtype(self):
name_dict = {
"a": {"random": [1]},
"b": {"random": [1, 2]},
"c": {"random": [1, None]},
"d": {"random": [None]},
"e": {"random": None},
"f": {"random": 0},
"g": {"random": -1},
"h": {"random": [-1]},
}
root = add_dict_to_tree_by_name(self.root, name_dict)
nodes = ["a", "b", "c", "d", "e", "f", "g", "h"]
expected_list = [[1], [1, 2], [1, None], None, None, 0, -1, [-1]]
for node_name, expected in zip(nodes, expected_list):
actual = find_name(root, node_name).get_attr("random")
assert expected == actual, f"Expected\n{expected}\nReceived\n{actual}"

def test_add_dict_to_tree_by_name_empty(self):
with pytest.raises(ValueError):
add_dict_to_tree_by_name(self.root, {})
Expand Down

0 comments on commit 092f41e

Please sign in to comment.