Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ quantile!(v::AbstractVector, p::Real; sorted::Bool=false, alpha::Real=1.0, beta:

# Function to perform partial sort of v for quantiles in given range
function _quantilesort!(v::AbstractVector, sorted::Bool, minp::Real, maxp::Real)
isempty(v) && throw(ArgumentError("empty data vector"))
length(v) == 0 && throw(ArgumentError("empty data vector"))
require_one_based_indexing(v)

if !sorted
Expand All @@ -1051,7 +1051,7 @@ end

n = length(v)

@assert n > 0 # this case should never happen here
n > 0 || throw(ArgumentError("quantile is undefined for a length-0 data vector"))

m = alpha + p * (one(alpha) - alpha - beta)
# Using fma here avoids some rounding errors when aleph is an integer
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,15 @@ end
@test quantile(skipmissing([1, missing, 2]), 0.5) === 1.5
@test quantile([1], 0.5) === 1.0

# length overflows to 0. Same error as an empty vector.
let r = typemin(Int):typemax(Int)
@test length(r) == 0
@test !isempty(r)
@test_throws ArgumentError("empty data vector") quantile!([0], r, [1])
@test_throws ArgumentError("empty data vector") quantile(r, 0.5; sorted=true)
end
@test_throws ArgumentError quantile(Int[], 0.5)

# make sure that type inference works correctly in normal cases
for T in [Int, BigInt, Float64, Float16, BigFloat, Rational{Int}, Rational{BigInt}]
for S in [Float64, Float16, BigFloat, Rational{Int}, Rational{BigInt}]
Expand Down
Loading