Loading phasik/utils/graphs.py +0 −26 Original line number Diff line number Diff line Loading @@ -6,36 +6,10 @@ import networkx as nx import pandas as pd __all__ = [ "create_graph_from_interactions", "graph_size_info", "weighted_edges_as_df", ] def create_graph_from_interactions(filename, sheet, source, target): """Create a networkx.Graph from an excel sheet describing edges Parameters ---------- filename : str Path to the excel file sheet : str Name of the sheet within the excel file source : str Name of the column containing the source nodes target : str Name of the column containing the target nodes Returns ------- graph : networkx.Graph """ interactions = pd.read_excel(filename, sheet_name=sheet) graph = nx.from_pandas_edgelist(interactions, source, target) return graph def graph_size_info(graph): """Return basic size info on about graph""" return f"{len(graph)} nodes and {len(graph.edges)} edges" Loading tests/utils/test_graphs.py +1 −2 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ def test_graph_size_info(): out1 = "15 nodes and 20 edges" out = pk.graph_size_info(input_graph) # Assert if the output matches the expected result assert out == out1 def test_weighted_edges_as_df(): Loading @@ -35,6 +34,6 @@ def test_weighted_edges_as_df(): # Call the function out = pk.weighted_edges_as_df(network_input) # Assert if the output matches the expected result pd.testing.assert_frame_equal(out1,out) Loading
phasik/utils/graphs.py +0 −26 Original line number Diff line number Diff line Loading @@ -6,36 +6,10 @@ import networkx as nx import pandas as pd __all__ = [ "create_graph_from_interactions", "graph_size_info", "weighted_edges_as_df", ] def create_graph_from_interactions(filename, sheet, source, target): """Create a networkx.Graph from an excel sheet describing edges Parameters ---------- filename : str Path to the excel file sheet : str Name of the sheet within the excel file source : str Name of the column containing the source nodes target : str Name of the column containing the target nodes Returns ------- graph : networkx.Graph """ interactions = pd.read_excel(filename, sheet_name=sheet) graph = nx.from_pandas_edgelist(interactions, source, target) return graph def graph_size_info(graph): """Return basic size info on about graph""" return f"{len(graph)} nodes and {len(graph.edges)} edges" Loading
tests/utils/test_graphs.py +1 −2 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ def test_graph_size_info(): out1 = "15 nodes and 20 edges" out = pk.graph_size_info(input_graph) # Assert if the output matches the expected result assert out == out1 def test_weighted_edges_as_df(): Loading @@ -35,6 +34,6 @@ def test_weighted_edges_as_df(): # Call the function out = pk.weighted_edges_as_df(network_input) # Assert if the output matches the expected result pd.testing.assert_frame_equal(out1,out)