Skip to content

Commit 8153488

Browse files
fix show for non-array (#564)
1 parent e46d1b0 commit 8153488

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ GraphNeuralNetworks/docs/src/GNNGraphs
1919
GraphNeuralNetworks/docs/src/GNNlib
2020
tutorials/docs/build
2121
prova.jl
22+
pyg.ipynb

GNNGraphs/src/gnngraph.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,20 @@ function Base.copy(g::GNNGraph; deep = false)
230230
end
231231
end
232232

233+
feature_summary(x::AbstractArray) = "$(dims2string(size(x)))"
234+
feature_summary(x::AbstractString) = "string($(length(x)))"
235+
feature_summary(x::T) where T = "$T"
236+
233237
function print_feature(io::IO, feature)
234238
if !isempty(feature)
235239
if length(keys(feature)) == 1
236240
k = first(keys(feature))
237241
v = first(values(feature))
238-
print(io, "$(k): $(dims2string(size(v)))")
242+
print(io, "$(k): $(feature_summary(v))")
239243
else
240244
print(io, "(")
241245
for (i, (k, v)) in enumerate(pairs(feature))
242-
print(io, "$k: $(dims2string(size(v)))")
246+
print(io, "$k: $(feature_summary(v))")
243247
if i == length(feature)
244248
print(io, ")")
245249
else

GNNGraphs/test/gnngraph.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ end
344344
@test g1 !== g2
345345
end
346346

347+
@testset "show" begin
348+
# no throw when global data is not an array
349+
g = rand_graph(10, 20, gdata = "ciao")
350+
@test sprint(show, g) == "GNNGraph(10, 20) with u: string(4) data"
351+
@test sprint(show, MIME("text/plain"), g) == "GNNGraph:\n num_nodes: 10\n num_edges: 20\n gdata:\n u = 4-codeunit String"
352+
end
353+
347354
## Cannot test this because DataStore is not an ordered collection
348355
## Uncomment when/if it will be based on OrderedDict
349356
# @testset "show" begin

0 commit comments

Comments
 (0)