Error broadcasting string getproperty using StructArrays

Another issue with my migration to StructArrays. There is one problem I don’t understand when trying to broadcast a function that gets a property and this property, specifically, is of type String. For example:

julia> struct A
         s::String
         i::Int
       end

julia> get_s(a::A) = a.s
get_s (generic function with 1 method)

julia> get_i(a::A) = a.i
get_i (generic function with 1 method)

julia> v1 = [ A("a",1), A("b",2) ]
2-element Vector{A}:
 A("a", 1)
 A("b", 2)

julia> using StructArrays

julia> v2 = StructArray(v1)
2-element StructArray(::Vector{String}, ::Vector{Int64}) with eltype A:
 A("a", 1)
 A("b", 2)

julia> get_s.(v2)
ERROR: DimensionMismatch("destination axes (1:0,) are not compatible with source axes (Base.OneTo(2),)")
Stacktrace:
 [1] throwdm(axdest::Tuple{UnitRange{Int64}}, axsrc::Tuple{Base.OneTo{Int64}})
   @ Base.Broadcast ./broadcast.jl:1060
 [2] copyto!
   @ ./broadcast.jl:972 [inlined]
 [3] copyto!
   @ ./broadcast.jl:936 [inlined]
 [4] copy
   @ ./broadcast.jl:908 [inlined]
 [5] materialize(bc::Base.Broadcast.Broadcasted{StructArrays.StructArrayStyle{Base.Broadcast.DefaultArrayStyle{1}}, Nothing, typeof(get_s), Tuple{StructVector{A, NamedTuple{(:s, :i), Tuple{Vector{String}, Vector{Int64}}}, Int64}}})
   @ Base.Broadcast ./broadcast.jl:883
 [6] top-level scope
   @ REPL[9]:1

Probably no need to demonstrate, but all other broadcasting operations and get calls work:

julia> get_s(v2[1])
"a"

julia> get_i.(v2)
2-element Vector{Int64}:
 1
 2

julia> get_s.(v1)
2-element Vector{String}:
 "a"
 "b"

julia> get_i.(v1)
2-element Vector{Int64}:
 1
 2


Have you tried it in a fresh REPL?

Yes, does that work for you? (forgot to add using StructArrays on the example above, will edit it now). But copying-pasting that gives me that error.

Ok, it seems there was a breaking change. Probably worth making an issue in repo?

I’ve got proper

julia> get_s.(v2)
2-element Vector{String}:
 "a"
 "b"

with add StructArrays@0.4.4 and your error with the current 0.5.1 version. So, something break during 0.4 -> 0.5 transition.

1 Like

Done: Error broadcasting string getproperty (regression) · Issue #189 · JuliaArrays/StructArrays.jl · GitHub