Skip value key in delete_none only during updates (#2264)

* Skip value only during update

* Update tests
This commit is contained in:
Freddy Boulton 2022-09-14 16:01:05 -05:00 committed by GitHub
parent 422de63663
commit 101bc7e287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 11 deletions

View File

@ -707,7 +707,9 @@ class Blocks(BlockContext):
== components._Keywords.NO_VALUE
):
prediction_value.pop("value")
prediction_value = delete_none(prediction_value)
prediction_value = delete_none(
prediction_value, skip_value=True
)
if "value" in prediction_value:
prediction_value["value"] = block.postprocess(
prediction_value["value"]

View File

@ -51,7 +51,6 @@ XRAY_CONFIG = {
"show_label": True,
"name": "image",
"visible": True,
"value": None,
"style": {},
},
},
@ -62,7 +61,6 @@ XRAY_CONFIG = {
"show_label": True,
"name": "json",
"visible": True,
"value": None,
"style": {},
},
},
@ -100,7 +98,6 @@ XRAY_CONFIG = {
"name": "image",
"visible": True,
"style": {},
"value": None,
},
},
{
@ -111,7 +108,6 @@ XRAY_CONFIG = {
"name": "json",
"visible": True,
"style": {},
"value": None,
},
},
{
@ -279,7 +275,6 @@ XRAY_CONFIG_DIFF_IDS = {
"type": "image",
"props": {
"image_mode": "RGB",
"value": None,
"source": "upload",
"tool": "editor",
"streaming": False,
@ -295,7 +290,6 @@ XRAY_CONFIG_DIFF_IDS = {
"type": "json",
"props": {
"show_label": True,
"value": None,
"name": "json",
"visible": True,
"style": {},
@ -339,7 +333,6 @@ XRAY_CONFIG_DIFF_IDS = {
"name": "image",
"visible": True,
"style": {},
"value": None,
},
},
{
@ -350,7 +343,6 @@ XRAY_CONFIG_DIFF_IDS = {
"name": "json",
"visible": True,
"style": {},
"value": None,
},
},
{

View File

@ -281,14 +281,14 @@ def format_ner_list(input_string: str, ner_groups: Dict[str : str | int]):
return output
def delete_none(_dict):
def delete_none(_dict, skip_value=False):
"""
Delete None values recursively from all of the dictionaries, tuples, lists, sets.
Credit: https://stackoverflow.com/a/66127889/5209347
"""
if isinstance(_dict, dict):
for key, value in list(_dict.items()):
if key == "value":
if skip_value and key == "value":
continue
if isinstance(value, (list, dict, tuple, set)):
_dict[key] = delete_none(value)