Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion traits not taken into account in 0.21 #3847

Open
3 tasks done
aplavin opened this issue May 9, 2024 · 5 comments · Fixed by #3859
Open
3 tasks done

conversion traits not taken into account in 0.21 #3847

aplavin opened this issue May 9, 2024 · 5 comments · Fixed by #3859
Labels

Comments

@aplavin
Copy link
Contributor

aplavin commented May 9, 2024

In 0.21, convert_argument(trait, args...) methods are not really called with user-specified arguments.
That's due to the new expand_dimensions function called before convert_arguments with conversion trait:

CT = conversion_trait(T, args...)
# Try to expand dimensions first, as this is the most basic step!
expanded = expand_dimensions(CT, args...)
!isnothing(expanded) && return convert_arguments(T, expanded...; kw...)
.

Noticed when trying to update KeyedArray conversions (in AxisKeysExtra.jl) to the new Makie version, specifically conversions like https://github.com/JuliaAPlavin/AxisKeysExtra.jl/blob/0000000065d69673f7f40c0f93f01ba0fbbbda34/ext/MakieExt.jl#L10-L13. MWE:

julia> using AxisKeys, Makie

julia> Makie.convert_arguments(ct::PointBased, x::KeyedArray{<:Any,1}) = convert_arguments(ct, only(axiskeys(x)), AxisKeys.keyless_unname(x))

julia> convert_arguments(Scatter, KeyedArray([1,2,3], x=10:10:30))
# 0.20, expected:
(Point{2, Float32}[[10.0, 1.0], [20.0, 2.0], [30.0, 3.0]],)
# 0.21, unexpected:
(10:10:30, Point{2, Float64}[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]])
  • are you running newest version (version from docs) ? bug only appears in 0.21, while 0.20 works fine
  • can you reproduce the bug with a fresh environment ? (]activate --temp; add Makie)
  • What platform + GPU are you on? any platform
@aplavin
Copy link
Contributor Author

aplavin commented May 24, 2024

Hmm, trying the most recent release – the underlying issue doesn't seem really fixed by that PR of mine...
Can we reopen this?

Example from the first post works, but actual plotting doesn't.

julia> using AxisKeys, Makie

julia> Makie.convert_arguments(ct::PointBased, x::KeyedArray{<:Any,1}) = convert_arguments(ct, only(axiskeys(x)), AxisKeys.keyless_unname(x))

julia> scatter(KeyedArray([1,2,3], x=10:10:30))
# Makie 0.20: shows the plot
# Makie 0.21.2: throws
ERROR: ArgumentError:     Conversion failed for Scatter (With conversion trait PointBased()) with args: Tuple{StepRange{Int64, Int64}, Vector{Point{2, Float64}}} .
    Scatter requires to convert to argument types Tuple{AbstractVector{<:Union{Point2, Point3}}}, which convert_arguments didn't succeed in.
    To fix this overload convert_arguments(P, args...) for Scatter or PointBased() and return an object of type Tuple{AbstractVector{<:Union{Point2, Point3}}}.`

Stacktrace:
 [1] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…}, recursion::Int64)
   @ Makie ~/.julia/packages/Makie/We6MY/src/interfaces.jl:240
 [2] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…}, recursion::Int64)
   @ Makie ~/.julia/packages/Makie/We6MY/src/interfaces.jl:233
 [3] conversion_pipeline(P::Type{…}, used_attrs::Tuple{}, args::Tuple{…}, args_obs::Tuple{…}, user_attributes::Dict{…}, deregister::Vector{…})
   @ Makie ~/.julia/packages/Makie/We6MY/src/interfaces.jl:213
 [4] (Scatter)(user_args::Tuple{KeyedArray{Int64, 1, NamedDimsArray{…}, Base.RefValue{…}}}, user_attributes::Dict{Symbol, Any})
   @ Makie ~/.julia/packages/Makie/We6MY/src/interfaces.jl:271
 [5] _create_plot(F::Function, attributes::Dict{Symbol, Any}, args::KeyedArray{Int64, 1, NamedDimsArray{…}, Base.RefValue{…}})
   @ Makie ~/.julia/packages/Makie/We6MY/src/figureplotting.jl:316
 [6] #scatter#72
   @ ~/.julia/packages/MakieCore/8S3xT/src/recipes.jl:436 [inlined]
 [7] scatter(args::KeyedArray{Int64, 1, NamedDimsArray{(:x,), Int64, 1, Vector{Int64}}, Base.RefValue{StepRange{Int64, Int64}}})
   @ MakieCore ~/.julia/packages/MakieCore/8S3xT/src/recipes.jl:434
 [8] top-level scope
   @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.

Any ideas on how to actually fix it? conversion_pipeline looks quite involved...

@aplavin
Copy link
Contributor Author

aplavin commented May 24, 2024

This time I don't even see a way to work around this issue... Any advice welcome!
Hope Makie intends to continue supporting convert_arguments stuff.

@asinghvi17 asinghvi17 reopened this May 25, 2024
@asinghvi17
Copy link
Member

asinghvi17 commented May 25, 2024

Defining Makie.expand_dimensions(::PointBased, k::KeyedArray) = (only(axiskeys(x)), AxisKeys.keyless_unname(x)) seems to fix it, though I imagine that's not the ideal way forward.

My guess is that KeyedArrays are hitting [7] expand_dimensions(::PointBased, y::AbstractVector{T} where T<:Real) @ ~/.julia/dev/Makie/src/interfaces.jl:136, since they are AbstractArrays...

@aplavin
Copy link
Contributor Author

aplavin commented May 25, 2024

Thanks for the suggestion, will try that!
It's kinda confusing, I thought convert_arguments should be applied first by design. Its goal is basically "convert user type to what we understand", while expand_dimensions seems to be "convert one type we understand to another".

@SimonDanisch
Copy link
Member

It's a separate step to divide a user defined type into it's x and y components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants