Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error broadcasting string getproperty (regression) #189

Closed
lmiq opened this issue Apr 27, 2021 · 2 comments · Fixed by #213
Closed

Error broadcasting string getproperty (regression) #189

lmiq opened this issue Apr 27, 2021 · 2 comments · Fixed by #213

Comments

@lmiq
Copy link

lmiq commented Apr 27, 2021

Seems that this works in version 0.4.4, but is broken in v0.5 (see this thread)

julia> struct A
         s::String
       end

julia> using StructArrays

julia> v = StructArray([A("a"),A("b")])
2-element StructArray(::Vector{String}) with eltype A:
 A("a")
 A("b")

julia> get_s(x) = x.s
get_s (generic function with 1 method)

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

julia> get_s.(v)
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,), Tuple{Vector{String}}}, Int64}}})
   @ Base.Broadcast ./broadcast.jl:883
 [6] top-level scope
   @ REPL[7]:1


@Arkoniak
Copy link

git bisect shows that breaking change was made in 0c4adf6

@piever
Copy link
Collaborator

piever commented Feb 20, 2022

Just figured out what this is while looking into other broadcast issues. Essentially, while materializing broadcast, we check whether the eltype is a struct type or not. Unfortunately, isstructtype(String) returns true, but fieldnames(String) == (). I confess I'm not entirely sure why isstructtype(String) returns true or whether there is a more reliable way to now if something was defined as a struct.

EDIT: it is enough to test that the struct type has at least a field, otherwise it is impossible to meaningfully collect it into a StructArray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants