Skip to content

Commit

Permalink
Remove checknan option to median and update docs
Browse files Browse the repository at this point in the history
Fixes #8598, closes #8605, ref #6820
  • Loading branch information
simonster committed Oct 7, 2014
1 parent 15b3226 commit e24fac0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
12 changes: 5 additions & 7 deletions base/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 6 additions & 7 deletions doc/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 5 additions & 7 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit e24fac0

Please sign in to comment.