Missings.T is unusable when T1 is a UnionAll
Closed this issue · 1 comments
iamed2 commented
julia [LibPQ]> u = Union{Array{Float64}, Missing}
Union{Array{Float64,N} where N, Missings.Missing}
julia [LibPQ]> Missings.T(u)
Array{Float64,N}
julia [LibPQ]> [21.0]::(Missings.T(u))
ERROR: TypeError: typeassert: expected Array{Float64,N}, got Array{Float64,1}
julia [LibPQ]> [21.0] isa Missings.T(u)
false
I think this behaviour would be ideal:
julia [LibPQ]> u = Union{Array{Float64}, Missing}
Union{Array{Float64,N} where N, Missings.Missing}
julia [LibPQ]> Missings.T(u)
Array{Float64,N} where N
julia [LibPQ]> [21.0]::(Missings.T(u))
1-element Array{Float64,1}:
21.0
julia [LibPQ]> [21.0] isa Missings.T(u)
true
nalimilan commented
On 0.7, the behavior is different (maybe worse, but at least less weird). I think it has to do with dispatch:
julia> T(::Type{Union{T1, Missing}}) where {T1} = T1
T (generic function with 1 method)
julia> u = Union{Array{Float64}, Missing}
Union{Missing, Array{Float64,N} where N}
julia> T(u)
ERROR: MethodError: no method matching T(::Type{Union{Missing, Array{Float64,N} where N}})
Closest candidates are:
T(::Type{Union{Missing, T1}}) where T1 at REPL[2]:1
Maybe file an issue in Julia?
Maybe we could work around this problem with a method dispatching on ::Union
. Could be worth investigating.