JuliaPlots / RecipesPipeline.jl

Utilities for processing recipes
http://juliaplots.org/RecipesPipeline.jl/dev/
MIT License
17 stars 17 forks source link

fix replacement of Union{Missing,Real} arrays so all missing arrays plot #116

Closed rafaqz closed 2 years ago

rafaqz commented 2 years ago

Currently plotting a heatmap with only missing values fails. Probably other series types too.

This is because map(float, a) on line 15 of series.jl - when run over a mixed type array containing only missing values returns an array of eltype Missing.

Instead, this PR makes a new array with the correct float type using similar, and broadcasts the ismissing and isnan checks from the old array to the new array. The removed mutability check wasn't actually relevant because map creates a new array anyway every time. So I removed it.

This is the current error solved by the PR. If you know where I should test this, let me know.


julia> a = ones(Union{Missing,Float64}, 100, 100);

julia> a .= missing;

julia> heatmap(a)
ERROR: MethodError: convert(::Type{Union{}}, ::Float64) is ambiguous. Candidates:
  convert(::Type{T}, x::Number) where T<:Number in Base at number.jl:7
  convert(::Type{T}, x::Number) where T<:AbstractChar in Base at char.jl:184
  convert(::Type{C}, c::Number) where C<:Colorant in ColorTypes at /home/raf/.julia/packages/ColorTypes/1dGw6/src/conversions.jl:74
  convert(::Type{<:Measures.Measure}, x::Float64) in Plots.PlotMeasures at /home/raf/.julia/packages/Plots/OeNV1/src/plotmeasures.jl:12
  convert(::Type{Union{}}, x) in Base at essentials.jl:216
  convert(::Type{T}, geom::X) where {T<:ArchGDAL.IGeometry, X} in ArchGDAL at /home/raf/.julia/packages/ArchGDAL/1I2FZ/src/geointerface.jl:286
  convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:19
Possible fix, define
  convert(::Type{Union{}}, ::Float64)
Stacktrace:
  [1] convert(#unused#::Type{Missing}, x::Float64)
    @ Base ./missing.jl:69
  [2] setindex!(A::Matrix{Missing}, x::Float64, i1::Int64)
    @ Base ./array.jl:903
  [3] _replace!(new::RecipesPipeline.var"#100#101", res::Matrix{Missing}, A::Matrix{Missing}, count::Int64)
    @ Base ./set.jl:681
  [4] replace!(new::Function, A::Matrix{Missing}; count::Int64)
    @ Base ./set.jl:531
  [5] replace!
    @ ./set.jl:531 [inlined]
  [6] _prepare_series_data
    @ ~/.julia/dev/RecipesPipeline/src/series.jl:15 [inlined]
  [7] _prepare_series_data
    @ ~/.julia/dev/RecipesPipeline/src/series.jl:20 [inlined]
  [8] _series_data_vector(x::Surface{Matrix{Union{Missing, Float64}}}, plotattributes::Dict{Symbol, Any})
    @ RecipesPipeline ~/.julia/dev/RecipesPipeline/src/series.jl:27
  [9] macro expansion
    @ ~/.julia/dev/RecipesPipeline/src/series.jl:128 [inlined]
 [10] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)
    @ RecipesPipeline ~/.julia/dev/RecipesPipeline/src/series.jl:116
 [11] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/dev/RecipesPipeline/src/user_recipe.jl:36
 [12] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline ~/.julia/dev/RecipesPipeline/src/RecipesPipeline.jl:70
 [13] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots ~/.julia/packages/Plots/OeNV1/src/plot.jl:208
 [14] plot(args::Any; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
    @ Plots ~/.julia/packages/Plots/OeNV1/src/plot.jl:91
 [15] heatmap(args::Any; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
    @ Plots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:410
 [16] heatmap(args::Any)
    @ Plots ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:410
 [17] top-level scope
    @ REPL[36]:1

@evetion this should fix your Rasters.jl plotting problem

t-bltg commented 2 years ago

Have you ran Plots.jl test suite with this PR applied ?

Can you also add tests for _prepare_series_data covering all types in https://github.com/JuliaPlots/RecipesPipeline.jl/blob/master/test/runtests.jl (they were never written, despite they should have been) ?

codecov-commenter commented 2 years ago

Codecov Report

Merging #116 (cda04de) into master (6253664) will increase coverage by 0.78%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #116      +/-   ##
==========================================
+ Coverage   62.35%   63.13%   +0.78%     
==========================================
  Files          10       10              
  Lines         526      529       +3     
==========================================
+ Hits          328      334       +6     
+ Misses        198      195       -3     
Impacted Files Coverage Δ
src/series.jl 76.25% <100.00%> (+4.82%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 44c404a...cda04de. Read the comment docs.

rafaqz commented 2 years ago

Plots.jl tests fail for me locally on unrelated GR problems.

But I've added some tests here for _prepare_series_data. There are some methods of _prepare_series_data remaining to test, e.g. for String and Volume. But they are not related and not within my knowledge, so I will leave them to someone else.

rafaqz commented 2 years ago

Can you approve my test runs? (or better, turn of that requirement in settings)

t-bltg commented 2 years ago

But I've added some tests here for _prepare_series_data. There are some methods of _prepare_series_data remaining to test, e.g. for String and Volume. But they are not related and not within my knowledge, so I will leave them to someone else.

Thanks, that's a start !

Can you approve my test runs? (or better, turn of that requirement in settings)

Yes, approved. Sorry, I don't have sufficient privileges for changing the settings :/

t-bltg commented 2 years ago

Plots.jl tests fail for me locally on unrelated GR problems

What I usually do is set the env var GKSwstype to nul before running the tests.

If that still fails I'll run the Plots tests tomorrow.