I’m implementing more advanced promotion rules in FlexUnits.jl but I’m getting stuck with functions like collect and map. If I put quantities in a vector with missing values, promotion rules I made give me a fully inferred element type.
julia> v = [1ud"m/s", 2ud"m/s", missing*ud"m/s", 4*ud"m/s"]
4-element Vector{Quantity{Union{Missing, Int64}, Units{Dimensions{FixRat32}, AffineTransform}}}:
1 m/s
2 m/s
missing m/s
4 m/s
This was achieved using
function Base.promote_rule(::Type{Quantity{T1,U}}, ::Type{Quantity{T2,U}}) where {T1, T2, U<:AbstractUnitLike}
return Quantity{promote_type(T1, T2), U}
end
However, if I try to map this multiplication out, I get a partially defined element type.
julia> v = map(x->x*ud"m/s", [1, 2, missing, 4])
4-element Vector{Quantity{T, Units{Dimensions{FixRat32}, AffineTransform}} where T}:
1 m/s
2 m/s
missing m/s
4 m/s
Even more unusual, if I have mixed values in the map (Float32 and Int64), promotion on map works as expected
julia> v = map(x->x*ud"m/s", [1, 2, Float32(3), 4])
4-element Vector{Quantity{Float32, Units{Dimensions{FixRat32}, AffineTransform}}}:
1.0 m/s
2.0 m/s
3.0 m/s
4.0 m/s
What do I have to do with “missing” in order to make map produce Quantity{Union{Int64,Missing}, U}?