Statistics.jl
Statistics.jl copied to clipboard
Make quantile return missing when input contains missing
As noted at https://github.com/JuliaLang/julia/pull/27515#discussion_r194235458, quantile should return missing rather than throwing an error when the input contains missing values, for consistency with median.
I am getting an error when calling quantile over an Array{Union{Missing,Float32}} that doesn't to actually contain any missing, but I am not using skipmissing, I have just used an index to the valid data. Is this the intent, or should I open a new issue:
From worker 3: MethodError: no method matching AbstractFloat(::Type{Union{Missing, Float32}})
From worker 3: Closest candidates are:
From worker 3: AbstractFloat(!Matched::Bool) at float.jl:250
From worker 3: AbstractFloat(!Matched::Int8) at float.jl:251
From worker 3: AbstractFloat(!Matched::Int16) at float.jl:252
From worker 3: ...
From worker 3: float(::Type) at ./float.jl:269
From worker 3: #quantile!#46(::Bool, ::Function, ::Array{Union{Missing, Float32},1}, ::Array{Float64,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:819
From worker 3: (::getfield(Statistics, Symbol("#kw##quantile!")))(::NamedTuple{(:sorted,),Tuple{Bool}}, ::typeof(Statistics.quantile!), ::Array{Union{Missing, Float32},1}, ::Array{Float64,1}) at ./none:0
From worker 3: #quantile#52(::Bool, ::Function, ::Array{Union{Missing, Float32},1}, ::Array{Float64,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:913
From worker 3: quantile(::Array{Union{Missing, Float32},1}, ::Array{Float64,1}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Statistics/src/Statistics.jl:913
Yes we should fix float(Union{Float64,Missing}). But that's a slightly different issue. There are probably more changes to do to get quantile to work in the presence of missing values.