thautwarm / PrettyPrint.jl

pretty print that makes sense
MIT License
21 stars 2 forks source link

Add support for StructArrays #2

Closed DilumAluthge closed 4 years ago

DilumAluthge commented 4 years ago

Would it be possible to add support for printing StructArrays? Currently it does not seem to work. Minimum working example:

julia> using PrettyPrint, StructArrays

julia> foo = ComplexF64(1, 2)
1.0 + 2.0im

julia> bar = ComplexF64(3, 4)
3.0 + 4.0im

julia> s = StructArray([foo, bar])
2-element StructArray(::Array{Float64,1}, ::Array{Float64,1}) with eltype Complex{Float64}:
 1.0 + 2.0im
 3.0 + 4.0im

julia> pprint(foo)
Complex{Float64}(
  re=1.0,
  im=2.0,
)
julia> pprint(bar)
Complex{Float64}(
  re=3.0,
  im=4.0,
)
julia> pprint(s)
StructArray{Complex{Float64},1,NamedTuple{(:re, :im),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}(
  fieldarrays=ERROR: type NamedTuple has no field fieldarrays
Stacktrace:
 [1] getproperty(::StructArray{Complex{Float64},1,NamedTuple{(:re, :im),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}, ::Symbol) at /Users/dilum/.julia/packages/StructArrays/OtfvU/src/structarray.jl:126
 [2] macro expansion at /Users/dilum/.julia/packages/PrettyPrint/kBEsL/src/PrettyPrint.jl:67 [inlined]
 [3] pprint_impl(::Base.TTY, ::StructArray{Complex{Float64},1,NamedTuple{(:re, :im),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}, ::Int64, ::Bool) at /Users/dilum/.julia/packages/PrettyPrint/kBEsL/src/PrettyPrint.jl:56
 [4] pprint(::Base.TTY, ::StructArray{Complex{Float64},1,NamedTuple{(:re, :im),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}, ::Int64, ::Bool) at /Users/dilum/.julia/packages/PrettyPrint/kBEsL/src/PrettyPrint.jl:88
 [5] pprint(::Base.TTY, ::StructArray{Complex{Float64},1,NamedTuple{(:re, :im),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}) at /Users/dilum/.julia/packages/PrettyPrint/kBEsL/src/PrettyPrint.jl:92
 [6] pprint(::StructArray{Complex{Float64},1,NamedTuple{(:re, :im),Tuple{Array{Float64,1},Array{Float64,1}}},Int64}) at /Users/dilum/.julia/packages/PrettyPrint/kBEsL/src/PrettyPrint.jl:96
 [7] top-level scope at REPL[25]:1

cc: @thautwarm

thautwarm commented 4 years ago

Hello. I'll support it. I shall use propertynames instead of fieldnames in the implementation.

https://github.com/thautwarm/PrettyPrint.jl/blob/master/src/PrettyPrint.jl#L58

This should be regarded as a bug of PrettyPrint.jl instead of enhancements.

Thanks for this report!

thautwarm commented 4 years ago

done.

DilumAluthge commented 4 years ago

Thanks!