AlgebraOfGraphics.jl
AlgebraOfGraphics.jl copied to clipboard
Can't use smooth() with ::Date axis
Bug description
MethodError is thrown when trying to use smooth() with a ::Date column mapped to an axis. Seem like I get to be the guinea pig to find the bugs in Dates interop :) (thanks for fixing #369 @piever!). I did ]dev AoG to make sure that #373 didn't fix this somehow.
Steps to reproduce
using AlgebraOfGraphics, CairoMakie, Dates
df = (x=[1, 2, 3],
y=collect(Date(2022,1,1):Day(1):Date(2022,1,3)))
draw(data(df) * mapping(:y, :x) * smooth())
Error reporting
ERROR: MethodError: no method matching float(::Type{Any})
Closest candidates are:
float(::Type{Union{Missing, T}}) where T at /opt/julia-1.7.2/share/julia/base/missing.jl:112
float(::Any) at /opt/julia-1.7.2/share/julia/base/float.jl:269
float(::Union{StatsBase.PValue, StatsBase.TestStat}) at ~/.julia/packages/StatsBase/pJqvO/src/statmodels.jl:86
...
Stacktrace:
[1] float(#unused#::Type{Any})
@ Base ./missing.jl:113
[2] loess(xs::Vector{Date}, ys::Vector{Int64}; kwargs::Base.Pairs{Symbol, Real, Tuple{Symbol, Symbol}, NamedTuple{(:span, :degree), Tuple{Float64, Int64}}})
@ Loess ~/.julia/packages/Loess/dv7Ad/src/Loess.jl:120
[3] (::AlgebraOfGraphics.var"#176#177"{AlgebraOfGraphics.SmoothAnalysis})(p::Vector{Vector}, #unused#::Dictionaries.Dictionary{Symbol, Any})
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/transformations/smooth.jl:10
[4] (::AlgebraOfGraphics.var"#78#79"{AlgebraOfGraphics.var"#176#177"{AlgebraOfGraphics.SmoothAnalysis}, ProcessedLayer})(c::CartesianIndex{1})
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/algebra/layer.jl:85
[5] iterate
@ ./generator.jl:47 [inlined]
[6] _collect(c::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, itr::Base.Generator{CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, AlgebraOfGraphics.var"#78#79"{AlgebraOfGraphics.var"#176#177"{AlgebraOfGraphics.SmoothAnalysis}, ProcessedLayer}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
@ Base ./array.jl:744
[7] collect_similar(cont::CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, itr::Base.Generator{CartesianIndices{1, Tuple{Base.OneTo{Int64}}}, AlgebraOfGraphics.var"#78#79"{AlgebraOfGraphics.var"#176#177"{AlgebraOfGraphics.SmoothAnalysis}, ProcessedLayer}})
@ Base ./array.jl:653
[8] map(f::Function, A::CartesianIndices{1, Tuple{Base.OneTo{Int64}}})
@ Base ./abstractarray.jl:2849
[9] map(f::AlgebraOfGraphics.var"#176#177"{AlgebraOfGraphics.SmoothAnalysis}, processedlayer::ProcessedLayer)
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/algebra/layer.jl:84
[10] (::AlgebraOfGraphics.SmoothAnalysis)(input::ProcessedLayer)
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/transformations/smooth.jl:8
[11] ProcessedLayer(layer::Layer)
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/algebra/layer.jl:64
[12] iterate
@ ./generator.jl:47 [inlined]
[13] collect(itr::Base.Generator{AlgebraOfGraphics.Layers, Type{ProcessedLayer}})
@ Base ./array.jl:724
[14] map
@ ./abstractarray.jl:2878 [inlined]
[15] compute_axes_grid(s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/algebra/layers.jl:97
[16] compute_axes_grid(fig::Figure, s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/algebra/layers.jl:84
[17] #233
@ ~/repos/AlgebraOfGraphics.jl/src/draw.jl:21 [inlined]
[18] update
@ ~/repos/AlgebraOfGraphics.jl/src/draw.jl:10 [inlined]
[19] plot!(fig::Figure, s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/draw.jl:21
[20] (::AlgebraOfGraphics.var"#237#238"{NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, Layer})(f::Figure)
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/draw.jl:46
[21] update
@ ~/repos/AlgebraOfGraphics.jl/src/draw.jl:10 [inlined]
[22] #draw#236
@ ~/repos/AlgebraOfGraphics.jl/src/draw.jl:45 [inlined]
[23] draw(s::Layer)
@ AlgebraOfGraphics ~/repos/AlgebraOfGraphics.jl/src/draw.jl:45
[24] top-level scope
@ REPL[9]:1
Version info
julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-10810U CPU @ 1.10GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
julia> using Pkg; Pkg.status()
Status `/tmp/jl_KnDH6U/Project.toml`
[cbdf2221] AlgebraOfGraphics v0.6.5 `../../home/adam/repos/AlgebraOfGraphics.jl`
[13f3f980] CairoMakie v0.7.5
Can workaround by manually using AlgebraOfGraphics.datetime2float in the mapping and using axis=(xticks=AlgebraOfGraphics.ticks(extrema(df.date)),).
This is an issue with LOESS which currently only accepts Float64. There's an open PR to fix this, but it only widens the accepted type to AbstractFloat. I might take a shot at making it truly generic, but I'm not sure off the top of my head if there's anything about the Loess algorithm that requires x and y to have the same dimensionality, so it may not be possible.