Skip to content

Inconsistent behavior with mean + skipmissing depending on the eltype #201

Description

@juliohm

MWE:

julia> x = Union{Float64,Missing}[missing]
1-element Vector{Union{Missing, Float64}}:
 missing

julia> mean(skipmissing(x))
NaN

julia> x = Missing[missing]
1-element Vector{Missing}:
 missing

julia> mean(skipmissing(x))
ERROR: ArgumentError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
 [1] _empty_reduce_error()
   @ Base ./reduce.jl:311
 [2] reduce_empty(::Base.MappingRF{typeof(identity), typeof(+)}, ::Type{Union{}})
   @ Base ./reduce.jl:314
 [3] reduce_empty_iter
   @ ./reduce.jl:373 [inlined]
 [4] mapreduce_empty_iter(f::Function, op::Function, itr::Base.SkipMissing{Vector{Missing}}, ItrEltype::Base.HasEltype)
   @ Base ./reduce.jl:369
 [5] mean(f::typeof(identity), itr::Base.SkipMissing{Vector{Missing}})
   @ Statistics ~/.julia/packages/Statistics/gbcbG/src/Statistics.jl:64
 [6] mean(itr::Base.SkipMissing{Vector{Missing}})
   @ Statistics ~/.julia/packages/Statistics/gbcbG/src/Statistics.jl:44
 [7] top-level scope
   @ REPL[17]:1

Transferred from JuliaLang/julia#60069

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions