Skip to content

Commit

Permalink
Add None to is_primitive to support null in conf/json files (#2111)
Browse files Browse the repository at this point in the history
* Add None to is_primitive to support null in conf/json files

* Update unit test
  • Loading branch information
YuanTingHsieh authored Oct 31, 2023
1 parent 13fdcdc commit d0e72fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion nvflare/tool/job/config/config_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,13 @@ def build_list_reverse_order_index(


def is_primitive(value):
return isinstance(value, int) or isinstance(value, float) or isinstance(value, str) or isinstance(value, bool)
return (
isinstance(value, int)
or isinstance(value, float)
or isinstance(value, str)
or isinstance(value, bool)
or value is None
)


def has_none_primitives_in_list(values: List):
Expand Down
5 changes: 3 additions & 2 deletions tests/unit_test/tool/job/config/config_indexer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_dict_indexer(self):
)

config = CF.from_dict(config_dict)
root_key = KeyIndex(key="", value=config, parent_key=None)
x_key = KeyIndex(key="x", value=config.get("x"), parent_key=None)

x1_key = KeyIndex(key="x1", value=config.get("x").get("x1"), parent_key=x_key)
Expand Down Expand Up @@ -149,6 +148,7 @@ def test_extract_file_from_dict_by_index(self):
"path": "df_statistics.DFStatistics",
"args": {
"data_path": "data.csv"
"other_path": null
}
},
{
Expand All @@ -164,8 +164,9 @@ def test_extract_file_from_dict_by_index(self):
"""
conf = CF.parse_string(config_str)
key_indices = build_dict_reverse_order_index(config=conf)
result = {}
exclude_key_list = []
result = filter_config_name_and_values(exclude_key_list, key_indices)
key_index = result["data_path"]
assert key_index.value == "data.csv"
key_index = result["other_path"]
assert key_index.value is None

0 comments on commit d0e72fd

Please sign in to comment.