Open
Description
openedon Aug 20, 2018
It seems that this issue must have been discussed, but I could not find any reference to it so I open it.
mean
behaves inconsistently between array and collection implementations in empty container case. This is especially relevant since missing
was introduced into base. Here is a code that shows the problem:
julia> using Statistics
julia> x = Union{Float64,Missing}[missing]
1-element Array{Union{Missing, Float64},1}:
missing
julia> mean(skipmissing(x))
ERROR: ArgumentError: mean of empty collection undefined: Base.SkipMissing{Array{Union{Missing, Float64},1}}(Union{Missing, Float64}[missing])
julia> mean(collect(skipmissing(x)))
NaN
Maybe a specialized implementation of mean
in case when eltype
of the collection is specified should be implemented? This is the case of skipmissing
which knows that its eltype
is Float64
. For instance sum
handles this case correctly (there is a special mapreduce
for this case with skipmissing
). Probably more functions in Statistics
should be reviewed, but first I would want to understand what is the intention with mean
.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment