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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Tree Plot: Plot tree using matplotlib library, added matplotlib as optional dependency.
- BaseNode: Add plot method.
### Changed:
- Misc: Rename assertion function.
- Misc: Optional dependencies imported as MagicMock

## [0.20.1] - 2024-08-24
Expand Down
6 changes: 3 additions & 3 deletions bigtree/dag/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from bigtree.utils.assertions import (
assert_dataframe_no_duplicate_attribute,
assert_dataframe_not_empty,
assert_key_not_in_dict_or_df,
assert_length_not_empty,
assert_not_reserved_keywords,
filter_attributes,
isnull,
)
Expand Down Expand Up @@ -109,7 +109,7 @@ def dict_to_dag(
parent_names: List[str] = []
if parent_key in node_attrs:
parent_names = node_attrs.pop(parent_key)
assert_key_not_in_dict_or_df(node_attrs, ["parent", "parents", "children"])
assert_not_reserved_keywords(node_attrs, ["parent", "parents", "children"])

if child_name in node_dict:
child_node = node_dict[child_name]
Expand Down Expand Up @@ -194,7 +194,7 @@ def dataframe_to_dag(
attribute_cols = list(data.columns)
attribute_cols.remove(child_col)
attribute_cols.remove(parent_col)
assert_key_not_in_dict_or_df(attribute_cols, ["parent", "parents", "children"])
assert_not_reserved_keywords(attribute_cols, ["parent", "parents", "children"])

data = data[[child_col, parent_col] + attribute_cols].copy()

Expand Down
15 changes: 8 additions & 7 deletions bigtree/utils/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
__all__ = [
"assert_style_in_dict",
"assert_str_in_list",
"assert_not_reserved_keywords",
"assert_key_in_dict",
"assert_length_not_empty",
"assert_dataframe_not_empty",
Expand Down Expand Up @@ -71,18 +72,18 @@ def assert_str_in_list(
)


def assert_key_not_in_dict_or_df(
parameter_dict: Union[Dict[str, Any], pd.DataFrame],
not_accepted_parameters: List[str],
def assert_not_reserved_keywords(
parameter_dict_or_df: Union[Dict[str, Any], pd.DataFrame],
reserved_keywords: List[str],
) -> None:
"""Raise ValueError is parameter is in key of dictionary

Args:
parameter_dict (Dict[str, Any]/pd.DataFrame): argument input for parameter
not_accepted_parameters (List[str]): list of not accepted parameters
parameter_dict_or_df (Dict[str, Any]/pd.DataFrame): argument input for parameter
reserved_keywords (List[str]): list of not accepted parameters
"""
for parameter in parameter_dict:
if parameter in not_accepted_parameters:
for parameter in parameter_dict_or_df:
if parameter in reserved_keywords:
raise ValueError(
f"Invalid input, check `{parameter}` is not a valid key as it is a reserved keyword"
)
Expand Down