MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.38k stars 302 forks source link

regression: 2d expand_dimensions ambiguity with custom types #4204

Open aplavin opened 3 weeks ago

aplavin commented 3 weeks ago

The new expand_dimension methods introduced in https://github.com/MakieOrg/Makie.jl/pull/4125, eg https://github.com/MakieOrg/Makie.jl/blob/2b5931ee92c00603a669d02b8103bff49315024b/src/interfaces.jl#L144, lead to ambiguities with expand_dimensions defined for custom array types. Ambiguities appear whenever one defines expand_dimesions(::GridBased, data::My2DArray). Presumably, this is the proper way to overload expand_dimesions for packages?

MWE with a KeyedArray:

julia> using Makie, AxisKeysExtra

julia> heatmap(KeyedArray(rand(2,2), x=1:2, y=1:2))
ERROR: MethodError: expand_dimensions(::CellGrid, ::KeyedArray{Float64, 2, NamedDimsArray{(:x, :y), Float64, 2, Matrix{Float64}}, Tuple{UnitRange{Int64}, UnitRange{Int64}}}) is ambiguous.

Candidates:
  expand_dimensions(ct::GridBased, x::KeyedArray{<:Any, 2})
    @ MakieExt ~/.julia/packages/AxisKeysExtra/qrSGg/ext/MakieExt.jl:42
  expand_dimensions(::Union{CellGrid, VertexGrid}, data::AbstractMatrix{<:Union{var"#s340", var"#s28"} where {var"#s340"<:Real, var"#s28"<:ColorTypes.Colorant}})
    @ Makie ~/.julia/packages/Makie/aG6xp/src/interfaces.jl:144

Possible fix, define
  expand_dimensions(::Union{CellGrid, VertexGrid}, ::KeyedArray{<:Union{var"#s340", var"#s28"} where {var"#s340"<:Real, var"#s28"<:ColorTypes.Colorant}, 2})

while it worked on earlier Makie versions.

asinghvi17 commented 3 weeks ago

I guess the union dispatch is causing issues. Wonder if that's really needed? Will look into it.