You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
julia> mean(skipmissing([missing, missing]))
ERROR: MethodError: reduce_empty(::typeof(Base.add_sum), ::Type{Union{}}) is ambiguous. Candidates:
reduce_empty(::typeof(Base.add_sum), ::Type{T}) where T<:Union{Int16, Int32, Int8} in Base at reduce.jl:231
reduce_empty(::typeof(Base.add_sum), ::Type{T}) where T<:Union{UInt16, UInt32, UInt8} in Base at reduce.jl:232
Possible fix, define
reduce_empty(::typeof(Base.add_sum), ::Type{Union{}})
Stacktrace:
[1] mapreduce_empty(::typeof(identity), ::Function, ::Type) at ./reduce.jl:247
[2] mapreduce_empty_iter(::Function, ::Function, ::Base.SkipMissing{Array{Missing,1}}, ::Base.HasEltype) at ./reduce.jl:254
[3] mean(::typeof(identity), ::Base.SkipMissing{Array{Missing,1}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/Statistics/src/Statistics.jl:60
[4] mean(::Base.SkipMissing{Array{Missing,1}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.3/Statistics/src/Statistics.jl:42
[5] top-level scope at REPL[110]:1
People use skipmissing to get away from worrying about missings. They shouldn't have to worry about whether or not the vector they are working with is full of missing values.
xref #35050. I would consider this part of a larger set of PRs I have in mind to make working with missings easier.
The text was updated successfully, but these errors were encountered:
This would probably be very easy to fix for all functions that use reduce, mapreduce or foldl. But I can't think of anything that would work on functions that just call for i in itr etc. But it's not hopeless:
julia> x = Union{Int, Missing}[missing, missing]
2-element Array{Union{Missing, Int64},1}:
missing
missing
julia> std(skipmissing(x))
NaN
julia> std(Int[])
NaN
My above example of [missing, missing] is bad, it's better to write mean(Union{Int, Missing}[missing, missing]) since there is dispatch based on the element type. For instance
julia> mean(skipmissing(x))
NaN
It's not obvious why mean of an empty iterator returns NaN. Imo it should return zero(eltype(itr)) but I guess there are larger concerns I don't undestand. The relevant line is here
People use
skipmissing
to get away from worrying aboutmissing
s. They shouldn't have to worry about whether or not the vector they are working with is full of missing values.xref #35050. I would consider this part of a larger set of PRs I have in mind to make working with
missing
s easier.The text was updated successfully, but these errors were encountered: