Skip to content

Commit 28d285d

Browse files
authored
Merge pull request #10 from JuliaGraphs/add_indexing
index :name attribute, closes #9
2 parents 075ec63 + 49062cd commit 28d285d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/GraphDataFrameBridge.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ function MetaGraph(
2727
`destination` is column symbol for destination of each edge
2828
2929
Will create a MetaGraph with a `name` property that stores node labels
30-
used in `origin` and `destination`.
30+
used in `origin` and `destination`. `name` is also set as an index property
31+
using `set_indexing_prop!`.
3132
3233
Note if `df` contains duplicated edge entries, the last record will
3334
overwrite previous entries.
@@ -112,7 +113,6 @@ function metagraph_from_dataframe(graph_type,
112113
set_prop!(mg, r[:vertex_id], :name, r[:name])
113114
end
114115

115-
116116
# Set edge attributes
117117
if typeof(edge_attributes) == Symbol
118118
edge_attributes = Vector{Symbol}([edge_attributes])
@@ -134,6 +134,9 @@ function metagraph_from_dataframe(graph_type,
134134
end
135135
end
136136

137+
# Set name as index (Issue #9)
138+
set_indexing_prop!(mg, :name)
139+
137140
return mg
138141
end
139142

test/graphdataframebridge.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
@test get_prop(mg, Edge(4, 5), :weight) == 4
5151
@test get_prop(mg, Edge(4, 5), :extraz) == 8
5252

53-
53+
# Test name column is indexed (Issue #9)
54+
@test mg["a", :name] == 1
55+
@test mg["b", :name] == 2
56+
5457
end

0 commit comments

Comments
 (0)