Skip to content

Commit 5cd6a89

Browse files
committed
fix issue with the overridden functions from Statistics
1 parent bab9b35 commit 5cd6a89

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

docs/src/man/missing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ julia> IMD.median(x)
8383

8484
### Some remarks
8585

86-
`var` and `std` will return `missing` when `dof = true` and an `AbstractVector{Union{T, Missing}}` of length one is passed as their argument. This is different from the behaviour of these functions defined in the `Statistics` package.
86+
`var` and `std` will return `missing` when `dof = true` and an `AbstractVector` of length one is passed as their argument. This is different from the behaviour of these functions defined in the `Statistics` package.
8787

8888
```jldoctest
89-
julia> IMD.var(Union{Missing, Int}[1])
89+
julia> IMD.var([1])
9090
missing
9191
92-
julia> IMD.std(Union{Missing, Int}[1])
92+
julia> IMD.std([1])
9393
missing
9494
95-
julia> var([1]) # fallback to Statistics.var
95+
julia> Statistics.var([1])
9696
NaN
9797
98-
julia> std([1]) # fallback to Statistics.std
98+
julia> Statistics.std([1])
9999
NaN
100100
```
101101

src/stat/stat.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,32 @@ sum(f, x)=Base.sum(f, x)
1818
sum(x::AbstractArray{Union{Missing, T},1}; threads = false) where T <: Union{INTEGERS, FLOATS} = threads ? hp_sum(identity, x) : stat_sum(identity, x)
1919
sum(x) = Base.sum(x)
2020

21-
Statistics.mean(f, x::AbstractArray{Union{T,Missing},1}) where T <: Union{INTEGERS, FLOATS} = stat_mean(f, x)
22-
Statistics.mean(x::AbstractArray{Union{T,Missing},1}) where T <: Union{INTEGERS, FLOATS} = stat_mean(x)
21+
mean(f, x::AbstractArray{Union{T,Missing},1}) where T <: Union{INTEGERS, FLOATS} = stat_mean(f, x)
22+
mean(x::AbstractArray{Union{T,Missing},1}) where T <: Union{INTEGERS, FLOATS} = stat_mean(x)
23+
mean(f, x) = Statistics.mean(f, x)
24+
mean(x) = Statistics.mean(x)
2325

2426
wsum(f, x::AbstractVector, w::AbstractVector) = stat_wsum(f, x, w)
2527
wsum(x::AbstractVector, w::AbstractVector) = stat_wsum(identity, x, w)
2628

2729
wmean(f, x::AbstractVector, w::AbstractVector) = stat_wmean(f, x, w)
2830
wmean(x::AbstractVector, w::AbstractVector) = stat_wmean(identity, x, w)
2931

30-
Statistics.var(f, x::AbstractArray{Union{T,Missing},1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_var(f, x, dof)
31-
Statistics.var(x::AbstractArray{Union{T,Missing},1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_var(x, dof)
32+
var(f, x::AbstractArray{Union{T,Missing},1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_var(f, x, dof)
33+
var(f, x::AbstractArray{T,1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_var(f, x, dof)
34+
var(x::AbstractArray{Union{T,Missing},1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_var(x, dof)
35+
var(x::AbstractArray{T,1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_var(x, dof)
36+
var(x, dof = true) = Statistics.var(x, corrected = dof)
3237

3338
std(f, x::AbstractArray{Union{T,Missing},1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_std(f, x, dof)
3439
std(x::AbstractArray{Union{T,Missing},1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_std(x, dof)
40+
std(f, x::AbstractArray{T,1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_std(f, x, dof)
41+
std(x::AbstractArray{T,1}, dof = true) where T <: Union{INTEGERS, FLOATS}= stat_std(x, dof)
3542

36-
Statistics.median(x::AbstractArray{Union{T,Missing},1}) where T = stat_median(x)
37-
Statistics.median!(x::AbstractArray{Union{T,Missing},1}) where T = stat_median!(x)
43+
median(x::AbstractArray{Union{T,Missing},1}) where T = stat_median(x)
44+
median!(x::AbstractArray{Union{T,Missing},1}) where T = stat_median!(x)
45+
median(x) = Statistics.median(x)
46+
median!(x) = Statistics.median!(x)
3847

3948

4049

0 commit comments

Comments
 (0)