diff --git a/src/stats/histograms.jl b/src/stats/histograms.jl index 334c2a0e..26ed751a 100644 --- a/src/stats/histograms.jl +++ b/src/stats/histograms.jl @@ -327,10 +327,10 @@ Ref: [http://www.jmlr.org/papers/volume11/ben-haim10a/ben-haim10a.pdf](http://ww using Plots plot(o) """ -struct KHist{T} <: HistogramStat{Number} +struct KHist{T, E<:Extrema{T}} <: HistogramStat{Number} bins::Vector{KHistBin{T}} b::Int - ex::Extrema{T} + ex::E end KHist(b::Int, T::Type = Float64) = KHist(KHistBin{T}[], b, Extrema(T)) diff --git a/src/stats/stats.jl b/src/stats/stats.jl index 24a11015..3eb00f88 100644 --- a/src/stats/stats.jl +++ b/src/stats/stats.jl @@ -361,12 +361,13 @@ Maximum and minimum. maximum(o) minimum(o) """ -mutable struct Extrema{T} <: OnlineStat{Number} +mutable struct Extrema{T,S} <: OnlineStat{S} min::T max::T n::Int end -Extrema(T::Type{<:Number} = Float64) = Extrema{T}(typemax.(T), typemin.(T), 0) +Extrema(T::Type{<:Number} = Float64) = Extrema{T,Number}(typemax.(T), typemin.(T), 0) +Extrema(T::Type) = Extrema{T,T}(typemax.(T), typemin.(T), 0) Extrema(initmin::T, initmax::T) where {T} = Extrema{T}(initmin, initmax, 0) function _fit!(o::Extrema, y) o.min = min(o.min, y) diff --git a/test/runtests.jl b/test/runtests.jl index 939df830..8492219e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -112,6 +112,10 @@ end @test value(fit!(Extrema(Int), z)) == extrema(z) @test ==(mergevals(Extrema(), y, y2)...) + + o = fit!(Extrema(Date), Date(2010):Day(1):Date(2011)) + @test minimum(o) == Date(2010) + @test maximum(o) == Date(2011) end #-----------------------------------------------------------------------# Fit[Dist] @testset "Fit[Dist]" begin