StatsBase.jl icon indicating copy to clipboard operation
StatsBase.jl copied to clipboard

Histogram fails with skipmissing

Open pdeffebach opened this issue 5 years ago • 3 comments

julia> using StatsBase

julia> fit(Histogram, [1, 1, 2])
Histogram{Int64,1,Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}
edges:
  1.0:0.5:2.5
weights: [2, 0, 1]
closed: left
isdensity: false

julia> fit(Histogram, skipmissing([1, 1, 2]))
ERROR: MethodError: no method matching fit(::Type{Histogram{Int64,N,E} where E where N}, ::Base.SkipMissing{Array{Int64,1}})

There is nothing about fitting a histogram that requires the array interface.

If there is a concern about working with weights, there is skipmissings in Missings.jl which allows you to sync up iterators with missing values.

pdeffebach avatar Nov 06 '20 18:11 pdeffebach

Could be actually a good moment to look at this, as https://github.com/JuliaStats/StatsBase.jl/pull/605 is fixed now.

mschauer avatar Nov 07 '20 13:11 mschauer

On master, I still get the same error.

julia> fit(Histogram, skipmissing([1, 2, 3]))
ERROR: MethodError: no method matching fit(::Type{Histogram{Int64,N,E} where E where N}, ::Base.SkipMissing{Array{Int64,1}})

I'm optimistic about making this work by removing some AbstractVector type annotations though. A quick search of the code doesn't reveal any length calls for the underlying data.

pdeffebach avatar Nov 07 '20 13:11 pdeffebach

Okay update length is called to calculate the optimal number of bins in the beginning. But after that things seem good.

pdeffebach avatar Nov 07 '20 14:11 pdeffebach