I am not sure but I imagine the idea behind doing this is returning the type that simplifies the array and will perform best after an operation.
Whatever the reason, I wonder what would be the best way to keep the type Union{Missing,T} when operating with Arrays regardless whether the Array contains missing values or not.
Yeah, I know, but problem is that if I do z = y .+ ϵ then z[end] = missing throws an error, which is what I want to avoid.
This is what allowmissing does in Missing.jl:
allowmissing(x::AbstractArray{T}) where {T} = convert(AbstractArray{Union{T, Missing}}, x)
I could convert directly instead loading a package but I was wondering if this is supposed to be the default behavior, I am asking because for certain algorithms I will have to constantly convert for every single operation I do with Arrays capable of containing missing values.
The right-hand side allocates a new vector, as such, its type may need shrinking or widening. In this case, the algorithm decided shrinking is useful (makes sense, because you didn’t have any missing to begin with)
I would say in analytics that’s debatable; precisely the whole point of defining Array{Union{Missing,T}} is because I am planing to insert missing values but I dot not want any type conversion every time my Arrays happen not to have any in an operation.
The workaround I am considering is using NaN isntead missing since NaN isa Number is true and I would not run into this kind of problems.