Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
colltoaction committed Dec 3, 2024
1 parent 16c2c0e commit fa3157c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
15 changes: 7 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,16 @@ def bipartite_graph4():

@pytest.fixture
def bipartite_dihypergraph1():
G = nx.Graph()
G.graph["network-type"] = "directed"
G = nx.DiGraph()
G.add_nodes_from([1, 2, 3, 4], bipartite=0)
G.add_nodes_from(["a", "b", "c"], bipartite=1)
G.add_edges_from([
(1, "a"),
(1, "b", {"direction": "tail"}),
(2, "b"),
(2, "c", {"direction": "tail"}),
(3, "c"),
(4, "a", {"direction": "tail"})])
("a", 1),
("b", 1, {"direction": "tail"}),
("b", 2),
("c", 2, {"direction": "tail"}),
("c", 3),
("a", 4, {"direction": "tail"})])
return G


Expand Down
12 changes: 6 additions & 6 deletions xgi/convert/bipartite_graph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Methods for converting to and from bipartite graphs."""

import networkx as nx
import xgi
from networkx import bipartite

from ..exception import XGIError
Expand Down Expand Up @@ -73,19 +74,18 @@ def from_bipartite_graph(G, create_using=None, dual=False):
else:
raise XGIError("Invalid type specifier")

if not bipartite.is_bipartite_node_set(G, nodes):
raise XGIError("The network is not bipartite")

network_type = G.graph.get("network-type")
if network_type == "directed":
if G.is_directed():
H = empty_dihypergraph(create_using)
else:
if not bipartite.is_bipartite_node_set(G, nodes):
raise XGIError("The network is not bipartite")

H = empty_hypergraph(create_using)

H.add_nodes_from(nodes)
for edge in edges:
for u, v, d in G.edges(edge, data="direction"):
if network_type == "directed":
if isinstance(H, xgi.DiHypergraph):
if d == "tail":
H.add_node_to_edge(u, v, direction="in")
else:
Expand Down

0 comments on commit fa3157c

Please sign in to comment.