11module GraphDataFrameBridge
2- import Graphs
2+ using Graphs
33using MetaGraphs
44using DataFrames
55export MetaGraph, MetaDiGraph
@@ -12,10 +12,10 @@ function MetaGraph(
1212 df:: DataFrame ,
1313 origin:: Symbol ,
1414 destination:: Symbol ;
15- weight:: Symbol = Symbol (),
16- edge_attributes:: Union{Vector{Symbol}, Symbol} = Vector {Symbol} (),
17- vertex_attributes:: DataFrame = DataFrame (),
18- vertex_id_col:: Symbol = Symbol ())
15+ weight:: Symbol = Symbol (),
16+ edge_attributes:: Union{Vector{Symbol},Symbol} = Vector {Symbol} (),
17+ vertex_attributes:: DataFrame = DataFrame (),
18+ vertex_id_col:: Symbol = Symbol ())
1919
2020 """
2121 MetaGraph(df, origin, destination)
@@ -56,10 +56,10 @@ function MetaDiGraph(
5656 df:: DataFrame ,
5757 origin:: Symbol ,
5858 destination:: Symbol ;
59- weight:: Symbol = Symbol (),
60- edge_attributes:: Union{Vector{Symbol}, Symbol} = Vector {Symbol} (),
61- vertex_attributes:: DataFrame = DataFrame (),
62- vertex_id_col:: Symbol = Symbol ())
59+ weight:: Symbol = Symbol (),
60+ edge_attributes:: Union{Vector{Symbol},Symbol} = Vector {Symbol} (),
61+ vertex_attributes:: DataFrame = DataFrame (),
62+ vertex_id_col:: Symbol = Symbol ())
6363
6464 """
6565 MetaDiGraph(df, origin, destination)
9696
9797
9898function metagraph_from_dataframe (graph_type,
99- df:: DataFrame ,
100- origin:: Symbol ,
101- destination:: Symbol ,
102- weight:: Symbol = Symbol (),
103- edge_attributes:: Union{Vector{Symbol}, Symbol} = Vector {Symbol} (),
104- vertex_attributes:: DataFrame = DataFrame (),
105- vertex_id_col:: Symbol = Symbol ())
99+ df:: DataFrame ,
100+ origin:: Symbol ,
101+ destination:: Symbol ,
102+ weight:: Symbol = Symbol (),
103+ edge_attributes:: Union{Vector{Symbol},Symbol} = Vector {Symbol} (),
104+ vertex_attributes:: DataFrame = DataFrame (),
105+ vertex_id_col:: Symbol = Symbol ())
106106
107107 # Map node names to vertex IDs
108108 nodes = sort! (unique! ([df[:, origin]; df[:, destination]]))
109- vertex_names = DataFrame (name= nodes, vertex_id= eachindex (nodes))
109+ vertex_names = DataFrame (name = nodes, vertex_id = eachindex (nodes))
110110
111111 # Merge in to original
112112 for c in [origin, destination]
113113 temp = rename (vertex_names, :vertex_id => Symbol (c, :_id ))
114- df = innerjoin (df, temp; on= c => :name )
114+ df = innerjoin (df, temp; on = c => :name )
115115 end
116116
117117 # Merge additional attributes to names
0 commit comments