Skip to content

Commit

Permalink
fix show for non-array (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello authored Dec 21, 2024
1 parent e46d1b0 commit 8153488
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ GraphNeuralNetworks/docs/src/GNNGraphs
GraphNeuralNetworks/docs/src/GNNlib
tutorials/docs/build
prova.jl
pyg.ipynb
8 changes: 6 additions & 2 deletions GNNGraphs/src/gnngraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,20 @@ function Base.copy(g::GNNGraph; deep = false)
end
end

feature_summary(x::AbstractArray) = "$(dims2string(size(x)))"
feature_summary(x::AbstractString) = "string($(length(x)))"
feature_summary(x::T) where T = "$T"

function print_feature(io::IO, feature)
if !isempty(feature)
if length(keys(feature)) == 1
k = first(keys(feature))
v = first(values(feature))
print(io, "$(k): $(dims2string(size(v)))")
print(io, "$(k): $(feature_summary(v))")
else
print(io, "(")
for (i, (k, v)) in enumerate(pairs(feature))
print(io, "$k: $(dims2string(size(v)))")
print(io, "$k: $(feature_summary(v))")
if i == length(feature)
print(io, ")")
else
Expand Down
7 changes: 7 additions & 0 deletions GNNGraphs/test/gnngraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ end
@test g1 !== g2
end

@testset "show" begin
# no throw when global data is not an array
g = rand_graph(10, 20, gdata = "ciao")
@test sprint(show, g) == "GNNGraph(10, 20) with u: string(4) data"
@test sprint(show, MIME("text/plain"), g) == "GNNGraph:\n num_nodes: 10\n num_edges: 20\n gdata:\n u = 4-codeunit String"
end

## Cannot test this because DataStore is not an ordered collection
## Uncomment when/if it will be based on OrderedDict
# @testset "show" begin
Expand Down

0 comments on commit 8153488

Please sign in to comment.