Skip to content

Functions applied to an empty skipmissing should return missing.  #35194

@pdeffebach

Description

@pdeffebach
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions