Commit 2e2598ca authored by Mattehub's avatar Mattehub
Browse files

Merge branch 'test_graphs' into 'master'

test utils/graphs.

See merge request !16
parents 77bf2aa3 72bd419d
Loading
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
@@ -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"
+1 −2
Original line number Diff line number Diff line
@@ -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():
@@ -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)