@@ -77,16 +77,19 @@ struct ToStruct{T,i,A} <: AbstractVector{T}
7777 data:: A # eltype is NamedTuple or some struct
7878end
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
8386Base. IndexStyle (:: Type{<:ToStruct} ) = Base. IndexLinear ()
8487Base. size (x:: ToStruct ) = (length (x. data),)
8588
8689Base. @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)
9093end
9194
9295arrowvector (:: 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