diff --git a/Project.toml b/Project.toml index 12c96773..56ff8442 100644 --- a/Project.toml +++ b/Project.toml @@ -6,8 +6,9 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [extras] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Random", "Test"] +test = ["Dates", "Random", "Test"] diff --git a/src/Statistics.jl b/src/Statistics.jl index b3bf26b3..16e87fbb 100644 --- a/src/Statistics.jl +++ b/src/Statistics.jl @@ -957,7 +957,7 @@ function _quantilesort!(v::AbstractArray, sorted::Bool, minp::Real, maxp::Real) sort!(v, 1, lv, Base.Sort.PartialQuickSort(lo:hi), Base.Sort.Forward) end ismissing(v[end]) && throw(ArgumentError("quantiles are undefined in presence of missing values")) - isnan(v[end]) && throw(ArgumentError("quantiles are undefined in presence of NaNs")) + applicable(isnan, v[end]) && isnan(v[end]) && throw(ArgumentError("quantiles are undefined in presence of NaNs")) return v end @@ -985,7 +985,7 @@ end b = v[j + 1] end - if isfinite(a) && isfinite(b) + if applicable(isfinite, a) && isfinite(a) && isfinite(b) return a + γ*(b-a) else return (1-γ)*a + γ*b diff --git a/test/runtests.jl b/test/runtests.jl index 3434bb76..660ee6c2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,6 +2,7 @@ using Statistics, Test, Random, LinearAlgebra, SparseArrays using Test: guardseed +using Dates Random.seed!(123) @@ -559,6 +560,8 @@ end @test quantile(skipmissing([1, missing, 2]), 0.5) === 1.5 @test quantile([1], 0.5) === 1.0 + @test quantile(Millisecond.(1:10), 0.5) == Millisecond(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}]