Skip to content

Commit 709abc7

Browse files
authored
bug: fix arc unpacking (#233)
Fixes a bug caused when the arc does not contain `nodes`
1 parent eb6adef commit 709abc7

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

datacommons_client/tests/endpoints/test_response.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ def test_flatten_arcs():
183183
assert result["dc/03lw9rhpendw5"].value == "191 Peachtree Tower"
184184

185185

186+
def test_unpack_arcs_missing_nodes_key():
187+
"""Test that unpack_arcs handles arcs with no 'nodes' key."""
188+
arcs = {
189+
"prop1": {
190+
"nodes": ["node1", "node2"]
191+
},
192+
"prop2": {
193+
# No 'nodes' key here
194+
},
195+
"prop3": {
196+
"nodes": []
197+
},
198+
}
199+
200+
result = unpack_arcs(arcs)
201+
assert result == {"prop1": ["node1", "node2"], "prop2": [], "prop3": []}
202+
203+
186204
def test_unpack_arcs_multiple_properties():
187205
"""Test that _unpack_arcs correctly handles multiple properties with nodes."""
188206
arcs = {

datacommons_client/utils/data_processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def unpack_arcs(arcs: Dict[str, Any]) -> Any:
77
"""Simplify the 'arcs' structure."""
88
if len(arcs) > 1:
99
# Multiple arcs: return dictionary of property nodes
10-
return {prop: arc_data["nodes"] for prop, arc_data in arcs.items()}
10+
return {prop: arc_data.get("nodes", []) for prop, arc_data in arcs.items()}
1111

1212
# Single arc: extract first node's data
1313
for property_data in arcs.values():

0 commit comments

Comments
 (0)