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

"Arguments must be sorted" error #552

Closed
korsbo opened this issue Sep 6, 2024 · 2 comments
Closed

"Arguments must be sorted" error #552

korsbo opened this issue Sep 6, 2024 · 2 comments

Comments

@korsbo
Copy link

korsbo commented Sep 6, 2024

Bug description

Hi,

draw throws with "Arguments must be sorted" for a strangely hard-to-pin-down combination of plot elements. This happens when plotting into multiple layouts but it seems to depend on how many plotting elements we have as well as how many subplots.

Steps to reproduce

using DataFrames
using CairoMakie
using AlgebraOfGraphics

n_subplots = 3
n_series = 10 # works fine with 2
n_x = 10
_test_df = DataFrame(rand(n_series * n_x, n_subplots), :auto)
_test_df[:, :color] = reduce(vcat, [fill(i, n_x) for i in 1:n_series])
_test_df[:, :x] = repeat(1:n_x, n_series)

plt = data(_test_df) * sum([
    mapping(:x, Symbol("x$i"), color = :color => string, layout=direct(('A':'Z')[i])) for i in 1:n_subplots
]) * visual(Lines)
draw(plt)

Error reporting

1-element ExceptionStack:
LoadError: ArgumentError: Arguments must be sorted
Stacktrace:
  [1] mergesorted(v1::Vector{String}, v2::Vector{String})
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/9G4sD/src/scales.jl:491
  [2] possibly_mergesorted
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/scales.jl:510 [inlined]
  [3] mergescales(c1::AlgebraOfGraphics.CategoricalScale{Vector{String}, Nothing}, c2::AlgebraOfGraphics.CategoricalScale{Vector{String}, Nothing})
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/9G4sD/src/scales.jl:366
  [4] compute_axes_grid(d::Layers, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/9G4sD/src/algebra/layers.jl:255
  [5] compute_axes_grid
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/algebra/layers.jl:233 [inlined]
  [6] compute_axes_grid(fig::Figure, d::Layers, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/9G4sD/src/algebra/layers.jl:205
  [7] compute_axes_grid
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/algebra/layers.jl:202 [inlined]
  [8] #346
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:20 [inlined]
  [9] update
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:10 [inlined]
 [10] plot!(fig::Figure, d::Layers, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/9G4sD/src/draw.jl:20
 [11] plot!
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:16 [inlined]
 [12] (::AlgebraOfGraphics.var"#351#352"{Dictionaries.Dictionary{Symbol, Any}, Dictionaries.Dictionary{Symbol, Any}, Dictionaries.Dictionary{Symbol, Any}, Dictionaries.Dictionary{Symbol, Any}, Layers, AlgebraOfGraphics.Scales})(f::Figure)
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:64
 [13] update
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:10 [inlined]
 [14] _draw(d::Layers, scales::AlgebraOfGraphics.Scales; axis::Dictionaries.Dictionary{Symbol, Any}, figure::Dictionaries.Dictionary{Symbol, Any}, facet::Dictionaries.Dictionary{Symbol, Any}, legend::Dictionaries.Dictionary{Symbol, Any}, colorbar::Dictionaries.Dictionary{Symbol, Any})
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:63
 [15] _draw
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:60 [inlined]
 [16] draw(d::Layers, scales::AlgebraOfGraphics.Scales; axis::@NamedTuple{}, figure::@NamedTuple{}, facet::@NamedTuple{}, legend::@NamedTuple{}, colorbar::@NamedTuple{}, palette::Nothing)
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/9G4sD/src/draw.jl:60
 [17] draw
    @ ~/data/.julia/packages/AlgebraOfGraphics/vP9dh/src/draw.jl:47 [inlined]
 [18] draw(d::Layers)
    @ AlgebraOfGraphics ~/data/.julia/packages/AlgebraOfGraphics/9G4sD/src/draw.jl:50

Version info

I get this on AoG 0.8.6, CairoMakie 0.12.9, Makie 0.21.9 with Julia 1.10.4 on Linux

@korsbo
Copy link
Author

korsbo commented Sep 6, 2024

I found a better way of doing this (mapping(:x, [:x1, :x2, :x3] ...)) so it's by no means urgent, but I still would not have expected the code above to throw for some values of n_series but not others.

@jkrumbiegel
Copy link
Member

Thanks for the reproducer, the problem was a bug in the sorting machinery. The reason it seemed to depend on the number of elements was just that it only appeared for strings that had to be naturally sorted, so you needed the "10" in there to trigger it. This will be fixed by #553

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

No branches or pull requests

2 participants