|
5 | 5 | from bigtree.node import node |
6 | 6 | from bigtree.tree.construct.dictionaries import add_dict_to_tree_by_name |
7 | 7 | from bigtree.tree.construct.strings import add_path_to_tree |
8 | | -from bigtree.utils import assertions |
| 8 | +from bigtree.utils import assertions, common |
9 | 9 |
|
10 | 10 | try: |
11 | 11 | import pandas as pd |
@@ -118,7 +118,7 @@ def add_dataframe_to_tree_by_path( |
118 | 118 |
|
119 | 119 | root_node = tree.root |
120 | 120 | for row in data.to_dict(orient="index").values(): |
121 | | - node_attrs = assertions.filter_attributes( |
| 121 | + node_attrs = common.filter_attributes( |
122 | 122 | row, omit_keys=["name", path_col], omit_null_values=True |
123 | 123 | ) |
124 | 124 | add_path_to_tree( |
@@ -191,7 +191,7 @@ def add_dataframe_to_tree_by_name( |
191 | 191 | .to_dict(orient="index") |
192 | 192 | ) |
193 | 193 | name_attrs = { |
194 | | - k1: {k2: v2 for k2, v2 in v1.items() if not assertions.isnull(v2)} |
| 194 | + k1: {k2: v2 for k2, v2 in v1.items() if not common.isnull(v2)} |
195 | 195 | for k1, v1 in name_attrs.items() |
196 | 196 | } |
197 | 197 |
|
@@ -283,7 +283,7 @@ def add_polars_to_tree_by_path( |
283 | 283 |
|
284 | 284 | root_node = tree.root |
285 | 285 | for row_kwargs in data.to_dicts(): |
286 | | - node_attrs = assertions.filter_attributes( |
| 286 | + node_attrs = common.filter_attributes( |
287 | 287 | row_kwargs, omit_keys=["name", path_col], omit_null_values=True |
288 | 288 | ) |
289 | 289 | add_path_to_tree( |
@@ -354,7 +354,7 @@ def add_polars_to_tree_by_name( |
354 | 354 | .rows_by_key(key=name_col, named=True) |
355 | 355 | ) |
356 | 356 | name_attrs = { |
357 | | - k1: {k2: v2 for k2, v2 in v1[0].items() if not assertions.isnull(v2)} |
| 357 | + k1: {k2: v2 for k2, v2 in v1[0].items() if not common.isnull(v2)} |
358 | 358 | for k1, v1 in name_attrs.items() |
359 | 359 | } |
360 | 360 |
|
@@ -446,15 +446,15 @@ def dataframe_to_tree( |
446 | 446 | root_node_kwargs = list( |
447 | 447 | root_node_data[attribute_cols].to_dict(orient="index").values() |
448 | 448 | )[0] |
449 | | - root_node_kwargs = assertions.filter_attributes( |
| 449 | + root_node_kwargs = common.filter_attributes( |
450 | 450 | root_node_kwargs, omit_keys=["name", path_col], omit_null_values=True |
451 | 451 | ) |
452 | 452 | root_node = node_type(root_name, **root_node_kwargs) |
453 | 453 | else: |
454 | 454 | root_node = node_type(root_name) |
455 | 455 |
|
456 | 456 | for row in data.to_dict(orient="index").values(): |
457 | | - node_attrs = assertions.filter_attributes( |
| 457 | + node_attrs = common.filter_attributes( |
458 | 458 | row, omit_keys=["name", path_col], omit_null_values=True |
459 | 459 | ) |
460 | 460 | add_path_to_tree( |
@@ -562,7 +562,7 @@ def _retrieve_attr(_row: Dict[str, Any]) -> Dict[str, Any]: |
562 | 562 | Returns: |
563 | 563 | Attribute dictionary |
564 | 564 | """ |
565 | | - node_attrs = assertions.filter_attributes( |
| 565 | + node_attrs = common.filter_attributes( |
566 | 566 | _row, omit_keys=[child_col, parent_col], omit_null_values=True |
567 | 567 | ) |
568 | 568 | node_attrs["name"] = _row[child_col] |
@@ -678,15 +678,15 @@ def polars_to_tree( |
678 | 678 | if len(root_node_data): |
679 | 679 | root_node_kwargs_list = root_node_data[attribute_cols].to_dicts() |
680 | 680 | root_node_kwargs = root_node_kwargs_list[0] if root_node_kwargs_list else {} |
681 | | - root_node_kwargs = assertions.filter_attributes( |
| 681 | + root_node_kwargs = common.filter_attributes( |
682 | 682 | root_node_kwargs, omit_keys=["name", path_col], omit_null_values=True |
683 | 683 | ) |
684 | 684 | root_node = node_type(root_name, **root_node_kwargs) |
685 | 685 | else: |
686 | 686 | root_node = node_type(root_name) |
687 | 687 |
|
688 | 688 | for row in data.to_dicts(): |
689 | | - node_attrs = assertions.filter_attributes( |
| 689 | + node_attrs = common.filter_attributes( |
690 | 690 | row, omit_keys=["name", path_col], omit_null_values=True |
691 | 691 | ) |
692 | 692 | add_path_to_tree( |
@@ -794,7 +794,7 @@ def _retrieve_attr(_row: Dict[str, Any]) -> Dict[str, Any]: |
794 | 794 | Returns: |
795 | 795 | Attribute dictionary |
796 | 796 | """ |
797 | | - node_attrs = assertions.filter_attributes( |
| 797 | + node_attrs = common.filter_attributes( |
798 | 798 | _row, omit_keys=[child_col, parent_col], omit_null_values=True |
799 | 799 | ) |
800 | 800 | node_attrs["name"] = _row[child_col] |
|
0 commit comments