diff --git a/CHANGELOG.md b/CHANGELOG.md index 87a4f8d6..05f06979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/bigtree/dag/construct.py b/bigtree/dag/construct.py index 060fc089..edaa0bd9 100644 --- a/bigtree/dag/construct.py +++ b/bigtree/dag/construct.py @@ -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, ) @@ -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] @@ -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() diff --git a/bigtree/utils/assertions.py b/bigtree/utils/assertions.py index a6ca31f2..ba68a339 100644 --- a/bigtree/utils/assertions.py +++ b/bigtree/utils/assertions.py @@ -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", @@ -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" )