Skip to content

Commit

Permalink
Fix issue with load_xgi_data HIF (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry authored Dec 10, 2024
1 parent e4b3c3b commit 943b64a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions tests/readwrite/test_xgi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def test_load_xgi_data(capfd):
assert collection["as-you-like-it"].num_nodes == 30
assert collection["as-you-like-it"].num_edges == 80

# test HIF
H = load_xgi_data("recipe-rec")
assert H.num_nodes == 9271
assert H.num_edges == 77733



@pytest.mark.skipif(
sys.version_info != (3, 12) and not platform.system() == "Linux",
Expand Down
26 changes: 13 additions & 13 deletions xgi/convert/hif_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def _convert_id(i, idtype):
network_type = "undirected"

if network_type in {"asc", "undirected"}:
G = Hypergraph()
H = Hypergraph()
elif network_type == "directed":
G = DiHypergraph()
H = DiHypergraph()

# Import network metadata
if "metadata" in data:
G._net_attr.update(data["metadata"])
H._net_attr.update(data["metadata"])

for record in data["incidences"]:
n = _convert_id(record["node"], nodetype)
Expand All @@ -123,9 +123,9 @@ def _convert_id(i, idtype):
if network_type == "directed":
d = record["direction"]
d = _convert_d(d) # convert from head/tail to in/out
G.add_node_to_edge(e, n, d)
H.add_node_to_edge(e, n, d)
else:
G.add_node_to_edge(e, n)
H.add_node_to_edge(e, n)

# import node attributes if they exist
if "nodes" in data:
Expand All @@ -136,10 +136,10 @@ def _convert_id(i, idtype):
else:
attr = {}

if n not in G._node:
G.add_node(n, **attr)
if n not in H._node:
H.add_node(n, **attr)
else:
G.set_node_attributes({n: attr})
H.set_node_attributes({n: attr})

# import edge attributes if they exist
if "edges" in data:
Expand All @@ -149,11 +149,11 @@ def _convert_id(i, idtype):
attr = record["attrs"]
else:
attr = {}
if e not in G._edge:
G.add_edge(_empty_edge(network_type), e, **attr)
if e not in H._edge:
H.add_edge(_empty_edge(network_type), e, **attr)
else:
G.set_edge_attributes({e: attr})
H.set_edge_attributes({e: attr})

if network_type == "asc":
G = SimplicialComplex(G)
return G
H = SimplicialComplex(H)
return H
2 changes: 1 addition & 1 deletion xgi/readwrite/xgi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _request_from_xgi_data(
jsondata = request_json_from_url(url)

if "incidences" in jsondata:
H = from_hif_dict(H, nodetype=nodetype, edgetype=edgetype)
H = from_hif_dict(jsondata, nodetype=nodetype, edgetype=edgetype)
if max_order:
H = cut_to_order(H, order=max_order)
return H
Expand Down

0 comments on commit 943b64a

Please sign in to comment.