Skip to content

Commit 0f2b22b

Browse files
alexhallamStefanKarpinski
authored andcommitted
Quantiles of vector of infinities (#19659)
Use naive interpolation formula in quantile when either endpoint of the interval is infinite, giving correct results when endpoints are infinite or NaN.
1 parent a033902 commit 0f2b22b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

base/statistics.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,18 @@ end
675675
f0 = (lv-1)*p # 0-based interpolated index
676676
t0 = trunc(f0)
677677
h = f0 - t0
678-
679678
i = trunc(Int,t0) + 1
680679

681680
if h == 0
682681
return T(v[i])
683682
else
684683
a = T(v[i])
685684
b = T(v[i+1])
686-
return a + ifelse(a == b, zero(a), h*(b-a))
685+
if isfinite(a) && isfinite(b)
686+
return a + h*(b-a)
687+
else
688+
return (1-h)*a + h*b
689+
end
687690
end
688691
end
689692

test/statistics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ end
329329
@test quantile(0.0:100.0, 0.0:0.1:1.0, sorted=true) == collect(0.0:10.0:100.0)
330330
@test quantile(100f0:-1f0:0.0, 0.0:0.1:1.0) == collect(0f0:10f0:100f0)
331331
@test quantile([Inf,Inf],0.5) == Inf
332-
332+
@test quantile([-Inf,1],0.5) == -Inf
333333
@test quantile([0,1],1e-18) == 1e-18
334334

335335
# StatsBase issue 164

0 commit comments

Comments
 (0)