Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 5296b2d

Browse files
author
George
authored
fix bug if the value is a dict (#447) (#448)
1 parent 91083c3 commit 5296b2d

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/sparsezoo/api/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ def map_keys(
4242
"""
4343
mapped_dict = {}
4444
for key, value in dictionary.items():
45-
if isinstance(value, List) or isinstance(value, Dict):
46-
value_type = type(value)
47-
mapped_dict[mapper(key)] = value_type(
45+
if isinstance(value, List):
46+
mapped_dict[mapper(key)] = [
4847
map_keys(dictionary=sub_dict, mapper=mapper) for sub_dict in value
49-
)
48+
]
49+
elif isinstance(value, Dict):
50+
mapped_dict[mapper(key)] = dict(map_keys(dictionary=value, mapper=mapper))
5051
else:
5152
mapped_dict[mapper(key)] = value
5253

tests/sparsezoo/api/test_graphql.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ def fetch(
121121
},
122122
"fields": None,
123123
},
124+
{
125+
"operation_body": "models",
126+
"arguments": {"stub": "zoo:mobilenet_v2-1.0-imagenet-base"},
127+
"fields": {"analysis": {"analysisId": None}},
128+
},
124129
],
125130
)
126131
def test_graphql_api_response(query_args: Dict[str, Any]):

tests/sparsezoo/api/test_query_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@
172172
),
173173
},
174174
),
175+
(
176+
{
177+
"operation_body": "models",
178+
"arguments": {"stub": "zoo:mobilenet_v2-1.0-imagenet-base"},
179+
"fields": {"analysis": {"analysisId": None}},
180+
},
181+
{
182+
"operation_body": "models",
183+
"arguments": '(stub: "zoo:mobilenet_v2-1.0-imagenet-base",)',
184+
"fields": "analysis { analysisId } ",
185+
},
186+
),
175187
],
176188
)
177189
def test_query_parser(

0 commit comments

Comments
 (0)