Skip to content

Commit e6b46a7

Browse files
author
Pietro Vertechi
authored
Merge pull request JuliaArrays#6 from KristofferC/kc/properties
add propertynames
2 parents 73775a2 + b288683 commit e6b46a7

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
@@ -45,3 +45,8 @@ f_infer() = StructArray{ComplexF64}(rand(2,2), rand(2,2))
4545
@testset "inferrability" begin
4646
@inferred f_infer()
4747
end
48+
49+
@testset "propertynames" begin
50+
a = StructArray{ComplexF64}(Float64[], Float64[])
51+
@test sort(collect(propertynames(a))) == [:im, :re]
52+
end

0 commit comments

Comments
 (0)