Plots.jl: histograms fail in the presence of NaNs

Created on 30 Oct 2017  路  10Comments  路  Source: JuliaPlots/Plots.jl

julia> a = randn(10);

julia> a[3] = NaN

julia> histogram(a)  #errors on the quantile call in in recipes.jl line 504
ERROR: ArgumentError: quantiles are undefined in presence of NaNs
Stacktrace:
 [1] #quantile!#546(::Bool, ::Function, ::Array{Float64,1}, ::Float64) at ./statistics.jl:688
 [2] (::Base.#kw##quantile!)(::Array{Any,1}, ::Base.#quantile!, ::Array{Float64,1}, ::Float64) at ./<missing>:0
 [3] #quantile#547(::Bool, ::Function, ::Array{Float64,1}, ::Float64) at ./statistics.jl:739
 [4] (::Plots.#_iqr#226)(::Array{Float64,1}) at /Users/michael/.julia/v0.6/Plots/src/recipes.jl:504
 [5] #_auto_binning_nbins#224(::Symbol, ::Function, ::Tuple{Array{Float64,1}}, ::Int64) at /Users/michael/.julia/v0.6/Plots/src/recipes.jl:528
 [6] (::Plots.#kw##_auto_binning_nbins)(::Array{Any,1}, ::Plots.#_auto_binning_nbins, ::Tuple{Array{Float64,1}}, ::Int64) at ./<missing>:0
 [7] map(::Plots.##230#231{Tuple{Array{Float64,1}},Symbol}, ::Tuple{Int64}) at ./tuple.jl:158
 [8] #_make_hist#232(::Bool, ::Void, ::Function, ::Tuple{Array{Float64,1}}, ::Symbol) at /Users/michael/.julia/v0.6/Plots/src/recipes.jl:550
 [9] (::Plots.#kw##_make_hist)(::Array{Any,1}, ::Plots.#_make_hist, ::Tuple{Array{Float64,1}}, ::Symbol) at ./<missing>:0
 [10] macro expansion at /Users/michael/.julia/v0.6/Plots/src/recipes.jl:566 [inlined]
 [11] apply_recipe(::Dict{Symbol,Any}, ::Type{Val{:barhist}}, ::UnitRange{Int64}, ::Array{Float64,1}, ::Void) at /Users/michael/.julia/v0.6/RecipesBase/src/RecipesBase.jl:287
 [12] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}) at /Users/michael/.julia/v0.6/Plots/src/pipeline.jl:406
 [13] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}) at /Users/michael/.julia/v0.6/Plots/src/pipeline.jl:415
 [14] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Float64,1}}) at /Users/michael/.julia/v0.6/Plots/src/plot.jl:231
 [15] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::Array{Float64,1}) at ./<missing>:0
 [16] #histogram#595(::Array{Any,1}, ::Function, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /Users/michael/.julia/v0.6/RecipesBase/src/RecipesBase.jl:381
 [17] histogram(::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /Users/michael/.julia/v0.6/RecipesBase/src/RecipesBase.jl:381

julia> histogram(a, bins = :scott) # avoids the quantile call but fails in StatsBase
ERROR: InexactError()
Stacktrace:
 [1] trunc(::Type{Int64}, ::Float64) at ./float.jl:672
 [2] nbitslen(::Float64, ::Int64) at ./twiceprecision.jl:61
 [3] nbitslen at ./twiceprecision.jl:58 [inlined]
 [4] floatrange(::Float64, ::Float64, ::Float64, ::Float64) at ./twiceprecision.jl:119
 [5] histrange(::Float64, ::Float64, ::Int64, ::Symbol) at /Users/michael/.julia/v0.6/StatsBase/src/hist.jl:115
 [6] histrange(::Array{Float64,1}, ::Int64, ::Symbol) at /Users/michael/.julia/v0.6/StatsBase/src/hist.jl:54
 [7] _hist_edge(::Tuple{Array{Float64,1}}, ::Int64, ::Int64) at /Users/michael/.julia/v0.6/Plots/src/recipes.jl:536
 [8] map(::Plots.##230#231{Tuple{Array{Float64,1}},Symbol}, ::Tuple{Int64}) at ./tuple.jl:158
 [9] #_make_hist#232(::Bool, ::Void, ::Function, ::Tuple{Array{Float64,1}}, ::Symbol) at /Users/michael/.julia/v0.6/Plots/src/recipes.jl:550
 [10] (::Plots.#kw##_make_hist)(::Array{Any,1}, ::Plots.#_make_hist, ::Tuple{Array{Float64,1}}, ::Symbol) at ./<missing>:0
 [11] macro expansion at /Users/michael/.julia/v0.6/Plots/src/recipes.jl:566 [inlined]
 [12] apply_recipe(::Dict{Symbol,Any}, ::Type{Val{:barhist}}, ::UnitRange{Int64}, ::Array{Float64,1}, ::Void) at /Users/michael/.julia/v0.6/RecipesBase/src/RecipesBase.jl:287
 [13] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}) at /Users/michael/.julia/v0.6/Plots/src/pipeline.jl:406
 [14] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}) at /Users/michael/.julia/v0.6/Plots/src/pipeline.jl:415
 [15] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Float64,1}}) at /Users/michael/.julia/v0.6/Plots/src/plot.jl:231
 [16] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::Array{Float64,1}) at ./<missing>:0
 [17] #histogram#595(::Array{Any,1}, ::Function, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at /Users/michael/.julia/v0.6/RecipesBase/src/RecipesBase.jl:381
 [18] (::Plots.#kw##histogram)(::Array{Any,1}, ::Plots.#histogram, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at ./<missing>:0
bug

All 10 comments

This also means that @df calls of tables in StatPlots containing NA's / NULL's will fail, as they are converted to NaNs. All of Plots is designed to work in the presence of NaNs.

I'll get on it.

I'm guessing the Plots quantile call is easy to fix, but possibly the StatsBase issue more complex?

Sorry, I didn't find any time to look into it yet - but I will, promise!

I just ran into this problem, is there a work around for this? I see there's been a lot of changes with missing values in Julia since this issue was opened.

@oschulz do you plan to fix this?

Sorry for the delay - yes!

Hi, I've just ran into it too. No big deal isnan() solves it. Just wanted to let you know.

OK, I fixed it - @oschulz will you review? https://github.com/JuliaPlots/Plots.jl/pull/1889

fixed

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lstagner picture lstagner  路  5Comments

kleinschmidt picture kleinschmidt  路  3Comments

kersulis picture kersulis  路  5Comments

dancsi picture dancsi  路  4Comments

nebuta picture nebuta  路  3Comments