Skip to content

Commit cc11ea9

Browse files
authored
propagate NaN value in median
1 parent 68869af commit cc11ea9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Statistics.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,8 @@ Like [`median`](@ref), but may overwrite the input vector.
814814
function median!(v::AbstractVector)
815815
isempty(v) && throw(ArgumentError("median of an empty array is undefined, $(repr(v))"))
816816
eltype(v)>:Missing && any(ismissing, v) && return missing
817-
any(x -> x isa Number && isnan(x), v) && return convert(eltype(v), NaN)
817+
nanix = findfirst(x -> x isa Number && isnan(x), v)
818+
isnothing(nanix) || return v[nanix]
818819
inds = axes(v, 1)
819820
n = length(inds)
820821
mid = div(first(inds)+last(inds),2)

0 commit comments

Comments
 (0)