Skip to content

Commit eae7259

Browse files
committed
allow building directed graph
1 parent 4c75160 commit eae7259

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

python/src/spark_dsg/networkx.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ def _fill_from_layer(G_out, layer):
6060
G_out.add_edge(edge.source, edge.target, **_convert_attr(edge.info))
6161

6262

63-
def graph_to_networkx(G_in, include_dynamic=True):
63+
def graph_to_networkx(G_in, include_dynamic=True, directed=False):
6464
"""Convert the DSG to a networkx representation."""
6565
nx = _get_networkx()
6666
if nx is None:
6767
return None
6868

69-
G_out = nx.Graph()
69+
G_out = nx.DiGraph() if directed else nx.Graph()
70+
7071
for layer in G_in.layers:
7172
_fill_from_layer(G_out, layer)
7273

@@ -85,12 +86,13 @@ def graph_to_networkx(G_in, include_dynamic=True):
8586
return G_out
8687

8788

88-
def layer_to_networkx(G_in):
89+
def layer_to_networkx(G_in, directed=False):
8990
"""Convert the DSG to a networkx representation."""
9091
nx = _get_networkx()
9192
if nx is None:
9293
return None
9394

94-
G_out = nx.Graph()
95+
G_out = nx.DiGraph() if directed else nx.Graph()
96+
9597
_fill_from_layer(G_out, G_in)
9698
return G_out

0 commit comments

Comments
 (0)