Skip to content

Commit b288683

Browse files
committed
add propertynames
1 parent 9b97568 commit b288683

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/structarray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ setindex!(s::StructArray, val, I::Int...) = set_ith!(s, val, I...)
4444
fields(::Type{<:NamedTuple{K}}) where {K} = K
4545
fields(::Type{<:StructArray{T}}) where {T} = fields(T)
4646

47+
Base.propertynames(s::StructArray) = fieldnames(typeof(columns(s)))
48+
4749
@generated function fields(t::Type{T}) where {T}
4850
return :($(Expr(:tuple, [QuoteNode(f) for f in fieldnames(T)]...)))
4951
end

test/runtests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ f_infer() = StructArray{ComplexF64}(rand(2,2), rand(2,2))
3636
@testset "inferrability" begin
3737
@inferred f_infer()
3838
end
39+
40+
@testset "propertynames" begin
41+
a = StructArray{ComplexF64}(Float64[], Float64[])
42+
@test sort(collect(propertynames(a))) == [:im, :re]
43+
end

0 commit comments

Comments
 (0)