This is a feature suggestion. I’m modeling database tables as a Vector
of NamedTuple
. I’m wondering if Julia could more smartly infer the type of these structures when values are missing
. For starters, I note that Julia is already great at inferring vectors that have missing
values; it finds elements of type Union{Missing, T}
. Further, Julia is very good at inferring types of vectors of tuples and even vectors of named tuples, so long as they don’t have missing
values.
julia> typeof([3, missing])
Array{Union{Missing, Int64},1}
julia> typeof([("A", 3), ("B", 4)])
Array{Tuple{String,Int64},1}
julia> typeof([(k="A", v=3), (k="B", v=4)])
Array{NamedTuple{(:k, :v),Tuple{String,Int64}},1}
The combination, a vector of tuples /w missing values, falls short.
julia> typeof([("A", 3), ("B", missing)])
Array{Tuple{String,Any},1}
julia> typeof([(k="A", v=3), (k="B", v=missing)])
Array{NamedTuple{(:k, :v),T} where T<:Tuple,1}
What I’d love to see instead…
# a future version of Julia
julia> typeof([("A", 3), ("B", missing)])
Array{Tuple{String,Union{Missing, Int64}},1}
julia> typeof([(k="A", v=3), (k="B", v=missing)])
Array{NamedTuple{(:k, :v),Tuple{String,Union{Missing, Int64}},1}
Is this at all related to https://github.com/JuliaLang/julia/issues/24614
or https://github.com/JuliaLang/julia/issues/25925?