Skip to content

Commit

Permalink
propagate NaN value in median
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin authored Mar 13, 2024
1 parent 68869af commit cc11ea9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,8 @@ Like [`median`](@ref), but may overwrite the input vector.
function median!(v::AbstractVector)
isempty(v) && throw(ArgumentError("median of an empty array is undefined, $(repr(v))"))
eltype(v)>:Missing && any(ismissing, v) && return missing
any(x -> x isa Number && isnan(x), v) && return convert(eltype(v), NaN)
nanix = findfirst(x -> x isa Number && isnan(x), v)
isnothing(nanix) || return v[nanix]
inds = axes(v, 1)
n = length(inds)
mid = div(first(inds)+last(inds),2)
Expand Down

0 comments on commit cc11ea9

Please sign in to comment.