Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fc88457
Add `AbstractVertex/EdgeDataGraph` const types.
jack-dunham May 14, 2026
5b628ca
Add some code comments.
jack-dunham May 15, 2026
fa19f5d
Make `AbstractVertexOrEdgeDataGraph` an abstract type; add concrete t…
jack-dunham May 15, 2026
0afcc35
Rename file.
jack-dunham May 15, 2026
b2e39d3
Tests and bug fixes.
jack-dunham May 15, 2026
f60063c
Version bump.
jack-dunham May 15, 2026
f704028
Fix regressions; add explicit imports.
jack-dunham May 15, 2026
b09f65f
Used `@eval` loop instead of union type to define Graph/DiGraph share…
jack-dunham May 18, 2026
1a060f9
Fix bug in `has_edge` definition; improve test converage.
jack-dunham May 18, 2026
8a890c3
Allow `setindex!` to upsert edges if vertices are present in `Abstrac…
jack-dunham May 18, 2026
1fc06be
Canonize `if ...; throw(); else ...; end` code patterns to `if ...; t…
jack-dunham May 18, 2026
cb16df3
Change `Type{<:Nothing}` to Type{Nothing}`.
jack-dunham May 18, 2026
41a4b5d
Improve code comments explaining `similar_graph(graph, VD, ED)` behav…
jack-dunham May 18, 2026
442deb9
Fix `similar_graph` fallbacks for `AbstractVertex/EdgeDataGraph` to r…
jack-dunham May 18, 2026
afbd747
Switch order of type params in `AbstractVertexOrEdgeDataGraph`.
jack-dunham May 18, 2026
8b1044e
Increase strictness of `DataView` key setting.
jack-dunham May 18, 2026
6fff2ce
Move vertex checking to `insert!_datagraph`.
jack-dunham May 18, 2026
9141efa
Fix `isinsertable` definitions.
jack-dunham May 19, 2026
fa73fc7
Add `forest_cover_edge_sequence` fallback for `AbstractDataGraph`
jack-dunham May 19, 2026
aae56ff
Interface clean up; fixes; tests
jack-dunham May 19, 2026
407b83f
Improve test coverage
jack-dunham May 19, 2026
9d7ff7b
Add tests for `copy`; deabstract `==` method.
jack-dunham May 19, 2026
fae5876
More tests and fixes.
jack-dunham May 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DataGraphs"
uuid = "b5a273c3-7e6c-41f6-98bd-8d7f1525a36a"
version = "0.4.2"
version = "0.4.3"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org> and contributors"]

[workspace]
Expand Down
3 changes: 3 additions & 0 deletions src/DataGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ include("dataview.jl")
include("abstractdatagraph.jl")
include("indexing.jl")
include("datagraph.jl")
include("abstractedgeorvertexdatagraph.jl")
include("vertexdatagraph.jl")
include("edgedatagraph.jl")
# TODO: Turn into an extension once `PartitionedGraphs` is excised.
include("lib/DataGraphsPartitionedGraphsExt/src/DataGraphsPartitionedGraphsExt.jl")

Expand Down
60 changes: 45 additions & 15 deletions src/abstractdatagraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ using NamedGraphs.GraphsExtensions: GraphsExtensions, add_edges!, add_vertices!,
using NamedGraphs.OrdinalIndexing: OrdinalSuffixedInteger
using NamedGraphs.SimilarType: similar_type
using NamedGraphs: NamedGraphs, AbstractEdges, AbstractNamedEdge, AbstractNamedGraph,
AbstractVertices, NamedDiGraph, NamedGraph, position_graph_type, similar_graph
AbstractVertices, NamedDiGraph, NamedGraph, Vertices, position_graph_type,
similar_graph, subgraph_edges
using SimpleTraits: SimpleTraits, @traitfn, Not

abstract type AbstractDataGraph{V, VD, ED} <: AbstractNamedGraph{V} end
Expand All @@ -21,12 +22,15 @@ edge_data_type(::Type{<:AbstractDataGraph{V, VD, ED}}) where {V, VD, ED} = ED
# TODO: Define for `AbstractGraph` as a `DataGraphInterface`.
underlying_graph(::AbstractDataGraph) = not_implemented()

# `isassigned`
is_vertex_assigned(::AbstractDataGraph, vertex) = not_implemented()
is_edge_assigned(::AbstractDataGraph, edge) = not_implemented()

# `getindex`
get_vertex_data(::AbstractDataGraph, vertex) = not_implemented()
get_edge_data(::AbstractDataGraph, edge) = not_implemented()

# `setindex!`
set_vertex_data!(::AbstractDataGraph, data, vertex) = not_implemented()
set_edge_data!(::AbstractDataGraph, data, edge) = not_implemented()

Expand All @@ -41,12 +45,6 @@ function get_edges_data(g::AbstractGraph, edges)
return map(e -> getindex(g, e), Indices(edges))
end

Graphs.has_vertex(g::AbstractDataGraph, vertex) = has_vertex(underlying_graph(g), vertex)
Graphs.has_edge(g::AbstractDataGraph, edge) = has_edge(underlying_graph(g), edge)
function Graphs.has_edge(g::AbstractDataGraph, edge::AbstractNamedEdge)
return has_edge(underlying_graph(g), edge)
end

vertex_data(dg::AbstractGraph) = VertexDataView(dg)
edge_data(dg::AbstractGraph) = EdgeDataView(dg)

Expand All @@ -57,9 +55,7 @@ function assigned_edges(graph::AbstractGraph)
return Indices(filter(e -> isassigned(graph, e), edges(graph)))
end

function Graphs.edgetype(graph::AbstractDataGraph)
return Graphs.edgetype(underlying_graph(graph))
end
Graphs.edgetype(graph::AbstractDataGraph) = edgetype(underlying_graph(graph))
function Graphs.edgetype(graph_type::Type{<:AbstractDataGraph})
return edgetype(underlying_graph_type(graph_type))
end
Expand All @@ -75,9 +71,38 @@ function NamedGraphs.position_graph_type(type::Type{<:AbstractDataGraph})
return position_graph_type(underlying_graph_type(type))
end

function Base.copyto!(dst_graph::AbstractDataGraph, src_graph::AbstractDataGraph)
vertex_data(dst_graph) .= vertex_data(src_graph)
edge_data(dst_graph) .= edge_data(src_graph)
function Base.copy(graph::AbstractDataGraph)
copy_graph = similar_graph(graph)
# Allow copies of graphs with undefined data.
copyto!(copy_graph, graph, assigned_vertices(graph))
copyto!(copy_graph, graph, assigned_edges(graph))
return copy_graph
end

# Base method to specialize on.
function Base.copyto!(graph_dst::AbstractDataGraph, src, keys)
for key in keys
graph_dst[key] = src[key]
end
return graph_dst
end

function Base.copyto!(graph_dst::AbstractDataGraph, src)
copyto!_datagraph(graph_dst, src)
return graph_dst
end

# To prevent method ambiguities
function copyto!_datagraph(dst::AbstractDataGraph, src::AbstractDataGraph)
if !issetequal(vertices(dst), vertices(src))
throw(ArgumentError("destination and source graphs must have the same vertices"))
end
copyto!(dst, src, vertices(src))
copyto!(dst, src, edges(src))
return dst
end
function copyto!_datagraph(dst_graph::AbstractDataGraph, src)
copyto!(dst_graph, src, keys(src))
return dst_graph
end

Expand Down Expand Up @@ -110,8 +135,8 @@ GraphsExtensions.convert_vertextype(::Type, ::AbstractDataGraph) = not_implement

function Base.:(==)(dg1::AbstractDataGraph, dg2::AbstractDataGraph)
underlying_graph(dg1) == underlying_graph(dg2) || return false
vertex_data(dg1) == vertex_data(dg2) || return false
edge_data(dg1) == edge_data(dg2) || return false
assigned_vertex_data(dg1) == assigned_vertex_data(dg2) || return false
assigned_edge_data(dg1) == assigned_edge_data(dg2) || return false
return true
end

Expand Down Expand Up @@ -426,3 +451,8 @@ function Base.show(io::IO, mime::MIME"text/plain", graph::AbstractDataGraph)
end

Base.show(io::IO, graph::AbstractDataGraph) = show(io, MIME"text/plain"(), graph)

function GraphsExtensions.forest_cover_edge_sequence(graph::AbstractDataGraph; kwargs...)
dummy_graph = add_edges!(NamedGraph(vertices(graph)), edges(graph))
return GraphsExtensions.forest_cover_edge_sequence(dummy_graph; kwargs...)
end
Comment on lines +455 to +458
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? Shouldn't the generic definition "just work"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because it's going to try and remove edges and that might not be defined. It is easier to just construct a dummy named graph as all this function does is return a list of edges.

Really it should return a list of edges of the same type as the input graph, though so maybe this needs to be rethought.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Probably that means that function should be rewritten to "just work" even for AbstractDataGraph, i.e. at worst it could first call add_edges!(NamedGraph(vertices(graph)), edges(graph)) and then run the rest of the function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I accidentally introduced an infinite method dispatch loop w.r.t this function in NamedGraphs so I need to make another PR anyway...

Loading
Loading