Skip to content

Commit c446f8c

Browse files
authored
Merge pull request #292 from kayjan/fix/assert-func
Rename assertion function
2 parents 6ab3adf + cdaaa13 commit c446f8c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Tree Plot: Plot tree using matplotlib library, added matplotlib as optional dependency.
1212
- BaseNode: Add plot method.
1313
### Changed:
14+
- Misc: Rename assertion function.
1415
- Misc: Optional dependencies imported as MagicMock
1516

1617
## [0.20.1] - 2024-08-24

bigtree/dag/construct.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from bigtree.utils.assertions import (
77
assert_dataframe_no_duplicate_attribute,
88
assert_dataframe_not_empty,
9-
assert_key_not_in_dict_or_df,
109
assert_length_not_empty,
10+
assert_not_reserved_keywords,
1111
filter_attributes,
1212
isnull,
1313
)
@@ -109,7 +109,7 @@ def dict_to_dag(
109109
parent_names: List[str] = []
110110
if parent_key in node_attrs:
111111
parent_names = node_attrs.pop(parent_key)
112-
assert_key_not_in_dict_or_df(node_attrs, ["parent", "parents", "children"])
112+
assert_not_reserved_keywords(node_attrs, ["parent", "parents", "children"])
113113

114114
if child_name in node_dict:
115115
child_node = node_dict[child_name]
@@ -194,7 +194,7 @@ def dataframe_to_dag(
194194
attribute_cols = list(data.columns)
195195
attribute_cols.remove(child_col)
196196
attribute_cols.remove(parent_col)
197-
assert_key_not_in_dict_or_df(attribute_cols, ["parent", "parents", "children"])
197+
assert_not_reserved_keywords(attribute_cols, ["parent", "parents", "children"])
198198

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

bigtree/utils/assertions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
__all__ = [
2727
"assert_style_in_dict",
2828
"assert_str_in_list",
29+
"assert_not_reserved_keywords",
2930
"assert_key_in_dict",
3031
"assert_length_not_empty",
3132
"assert_dataframe_not_empty",
@@ -71,18 +72,18 @@ def assert_str_in_list(
7172
)
7273

7374

74-
def assert_key_not_in_dict_or_df(
75-
parameter_dict: Union[Dict[str, Any], pd.DataFrame],
76-
not_accepted_parameters: List[str],
75+
def assert_not_reserved_keywords(
76+
parameter_dict_or_df: Union[Dict[str, Any], pd.DataFrame],
77+
reserved_keywords: List[str],
7778
) -> None:
7879
"""Raise ValueError is parameter is in key of dictionary
7980
8081
Args:
81-
parameter_dict (Dict[str, Any]/pd.DataFrame): argument input for parameter
82-
not_accepted_parameters (List[str]): list of not accepted parameters
82+
parameter_dict_or_df (Dict[str, Any]/pd.DataFrame): argument input for parameter
83+
reserved_keywords (List[str]): list of not accepted parameters
8384
"""
84-
for parameter in parameter_dict:
85-
if parameter in not_accepted_parameters:
85+
for parameter in parameter_dict_or_df:
86+
if parameter in reserved_keywords:
8687
raise ValueError(
8788
f"Invalid input, check `{parameter}` is not a valid key as it is a reserved keyword"
8889
)

0 commit comments

Comments
 (0)