From e24fac0f1bb7200e1597d8e546cd445ce4fc0fc0 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Tue, 7 Oct 2014 18:00:05 -0400 Subject: [PATCH] Remove checknan option to median and update docs Fixes #8598, closes #8605, ref #6820 --- base/statistics.jl | 12 +++++------- doc/helpdb.jl | 13 ++++++------- doc/stdlib/base.rst | 12 +++++------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/base/statistics.jl b/base/statistics.jl index 83e5aeb7405f2..300624edf2639 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -455,10 +455,10 @@ middle(x::Real, y::Real) = (x + y) / 2 middle(a::Range) = middle(a[1], a[end]) middle(a::AbstractArray) = ((v1, v2) = extrema(a); middle(v1, v2)) -function median!{T}(v::AbstractVector{T}; checknan::Bool=true) +function median!{T}(v::AbstractVector{T}) isempty(v) && error("median of an empty array is undefined") - if checknan && T<:FloatingPoint - for x in v + if T<:FloatingPoint + @inbounds for x in v isnan(x) && return x end end @@ -471,10 +471,8 @@ function median!{T}(v::AbstractVector{T}; checknan::Bool=true) end end -median{T}(v::AbstractArray{T}; checknan::Bool=true) = - median!(vec(copy(v)), checknan=checknan) -median{T}(v::AbstractArray{T}, region; checknan::Bool=true) = - mapslices( x->median(x; checknan=checknan), v, region ) +median{T}(v::AbstractArray{T}) = median!(vec(copy(v))) +median{T}(v::AbstractArray{T}, region) = mapslices(median, v, region) # for now, use the R/S definition of quantile; may want variants later # see ?quantile in R -- this is type 7 diff --git a/doc/helpdb.jl b/doc/helpdb.jl index d8fc20d0cb9a2..9ac2cbc44178b 100644 --- a/doc/helpdb.jl +++ b/doc/helpdb.jl @@ -6612,17 +6612,16 @@ popdisplay(d::Display) "), -("Base","median","median(v; checknan::Bool=true) +("Base","median","median(v) - Compute the median of a vector \"v\". If keyword argument - \"checknan\" is true (the default), an error is raised for data - containing NaN values. Note: Julia does not ignore \"NaN\" values - in the computation. For applications requiring the handling of - missing data, the \"DataArray\" package is recommended. + Compute the median of a vector \"v\". \"NaN\" is returned if the + data contains any \"NaN\" values. For applications requiring the + handling of missing data, the \"DataArrays\" package is + recommended. "), -("Base","median!","median!(v; checknan::Bool=true) +("Base","median!","median!(v) Like \"median\", but may overwrite the input vector. diff --git a/doc/stdlib/base.rst b/doc/stdlib/base.rst index 7d63fb45019f2..5e1dfca01a025 100644 --- a/doc/stdlib/base.rst +++ b/doc/stdlib/base.rst @@ -4561,15 +4561,13 @@ Statistics Compute the sample variance of a vector ``v`` with known mean ``m``. Note: Julia does not ignore ``NaN`` values in the computation. -.. function:: median(v; checknan::Bool=true) +.. function:: median(v) - Compute the median of a vector ``v``. If keyword argument ``checknan`` is true - (the default), an error is raised for data containing NaN values. - Note: Julia does not ignore ``NaN`` values in the computation. - For applications requiring the handling of missing data, the ``DataArray`` - package is recommended. + Compute the median of a vector ``v``. ``NaN`` is returned if the data + contains any ``NaN`` values. For applications requiring the handling of + missing data, the ``DataArrays`` package is recommended. -.. function:: median!(v; checknan::Bool=true) +.. function:: median!(v) Like ``median``, but may overwrite the input vector.