Skip to content

Commit 78e22be

Browse files
committed
improved support for struct columns with missing values
1 parent ac199b0 commit 78e22be

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
name = "Arrow"
1818
uuid = "69666777-d1a9-59fb-9406-91d4454c9d45"
1919
authors = ["quinnj <quinn.jacobd@gmail.com>"]
20-
version = "2.7.1"
20+
version = "2.7.2"
2121

2222
[deps]
2323
ArrowTypes = "31f734f8-188a-4ce0-8406-c8a06bd891cd"

src/arraytypes/struct.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,19 @@ struct ToStruct{T,i,A} <: AbstractVector{T}
7777
data::A # eltype is NamedTuple or some struct
7878
end
7979

80-
ToStruct(x::A, j::Integer) where {A} =
81-
ToStruct{fieldtype(Base.nonmissingtype(eltype(A)), j),j,A}(x)
80+
function ToStruct(x::A, j::Integer, hasmissing::Bool=false) where {A}
81+
AT = fieldtype(eltype(A), j)
82+
T = hasmissing ? Union{Missing,AT} : AT
83+
ToStruct{T,j,A}(x)
84+
end
8285

8386
Base.IndexStyle(::Type{<:ToStruct}) = Base.IndexLinear()
8487
Base.size(x::ToStruct) = (length(x.data),)
8588

8689
Base.@propagate_inbounds function Base.getindex(A::ToStruct{T,j}, i::Integer) where {T,j}
8790
@boundscheck checkbounds(A, i)
8891
@inbounds x = A.data[i]
89-
return x === missing ? ArrowTypes.default(T) : getfield(x, j)
92+
ismissing(x) ? missing : getfield(x, j)
9093
end
9194

9295
arrowvector(::StructKind, x::Struct, i, nl, fi, de, ded, meta; kw...) = x
@@ -102,9 +105,10 @@ function arrowvector(::StructKind, x, i, nl, fi, de, ded, meta; kw...)
102105
len = length(x)
103106
validity = ValidityBitmap(x)
104107
T = Base.nonmissingtype(eltype(x))
108+
hasmissing = Missing <: eltype(x)
105109
data = Tuple(
106-
arrowvector(ToStruct(x, j), i, nl + 1, j, de, ded, nothing; kw...) for
107-
j = 1:fieldcount(T)
110+
arrowvector(ToStruct(x, j, hasmissing), i, nl + 1, j, de, ded, nothing; kw...)
111+
for j = 1:fieldcount(T)
108112
)
109113
NT = namedtupletype(T, data)
110114
return Struct{withmissing(eltype(x), NT),typeof(data),fieldnames(NT)}(

0 commit comments

Comments
 (0)