Skip to content

Commit efda46e

Browse files
authored
fix nested structarrays broadcasting (#249)
1 parent 5c88775 commit efda46e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/structarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ Base.@pure cst(::Type{SA}) where {SA} = combine_style_types(array_types(SA).para
505505

506506
BroadcastStyle(::Type{SA}) where {SA<:StructArray} = StructArrayStyle{typeof(cst(SA)), ndims(SA)}()
507507

508-
function Base.similar(bc::Broadcasted{StructArrayStyle{S, N}}, ::Type{ElType}) where {S<:DefaultArrayStyle, N, ElType}
508+
function Base.similar(bc::Broadcasted{StructArrayStyle{S, N}}, ::Type{ElType}) where {S<:Union{DefaultArrayStyle,StructArrayStyle}, N, ElType}
509509
ContainerType = isnonemptystructtype(ElType) ? StructArray{ElType} : Array{ElType}
510510
return similar(ContainerType, axes(bc))
511511
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,9 @@ Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{MyArray}}, ::Type{El
11421142
# issue #189
11431143
v = StructArray([(a="s1",), (a="s2",)])
11441144
@test @inferred(broadcast(el -> el.a, v)) == ["s1", "s2"]
1145+
1146+
@test identity.(StructArray(x=StructArray(a=1:3)))::StructArray == [(x=(a=1,),), (x=(a=2,),), (x=(a=3,),)]
1147+
@test (x -> x.x.a).(StructArray(x=StructArray(a=1:3))) == [1, 2, 3]
11451148
end
11461149

11471150
@testset "map" begin

0 commit comments

Comments
 (0)