From ad81ac8563611cdb15ec4396d769789eeb2365ef Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Tue, 29 Sep 2020 13:32:04 -0400 Subject: [PATCH 1/2] Only check isnan if applicable --- Project.toml | 3 ++- src/Statistics.jl | 2 +- test/runtests.jl | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) 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..4068154c 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 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}] From 500fb815c286c302c24498b83d68db189f63195d Mon Sep 17 00:00:00 2001 From: Ian Fiske <135570+ianfiske@users.noreply.github.com> Date: Wed, 30 Sep 2020 13:37:07 -0400 Subject: [PATCH 2/2] Add another lookahead dispatch check --- src/Statistics.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Statistics.jl b/src/Statistics.jl index 4068154c..16e87fbb 100644 --- a/src/Statistics.jl +++ b/src/Statistics.jl @@ -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