Skip to content

Commit

Permalink
adding translation of network object to/from networkx
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanovaos committed Sep 4, 2024
1 parent 078f96e commit b481e2a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Empty file.
12 changes: 12 additions & 0 deletions networkcommons/network/_formats/_networkx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import networkx as nx

def to_networkx(
net: "NetworkBase",
node_attr: list[str] = None,
edge_attr: list[str] = None) -> nx.Graph:
netx = nx.Graph()
return netx


def from_networkx():
pass
18 changes: 18 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
import networkx as nx
from networkcommons.network._formats._networkx import to_networkx
from networkcommons.network._network import NetworkBase

@pytest.fixture
def small_network():
nodes = ['A', 'B', 'C']
edges = [('A', 'B'), ('B', 'C')]
network = NetworkBase(edges = edges, nodes = nodes)
return network


def test_to_networkx(small_network):
#create a networkbase object
#convert it to networkx
netx = to_networkx(small_network)
assert isinstance(netx, nx.Graph)

0 comments on commit b481e2a

Please sign in to comment.