Skip to content

Commit

Permalink
Merge pull request #292 from kayjan/fix/assert-func
Browse files Browse the repository at this point in the history
Rename assertion function
  • Loading branch information
kayjan authored Aug 25, 2024
2 parents 6ab3adf + cdaaa13 commit c446f8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
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

0 comments on commit c446f8c

Please sign in to comment.