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

Unable to select multiple columns in mapping #362

Open
rongcuid opened this issue Feb 26, 2022 · 2 comments
Open

Unable to select multiple columns in mapping #362

rongcuid opened this issue Feb 26, 2022 · 2 comments

Comments

@rongcuid
Copy link

Bug description

When trying to specify multiple columns for attrs like color, I am unable to do so:

df1 = DataFrame(a=[1, 2], b=[3, 4], c = ["x","y"], d = ["z", "w"])
data(df1) * mapping(:a, :b, color = [:c, :d] => (c, d) -> collect(zip(c, d))) |> draw

The following error is produced:

ERROR: MethodError: no method matching select(::DataFrames.DataFrameColumns{DataFrame}, ::Vector{Symbol})
Closest candidates are:
  select(::Any, ::AlgebraOfGraphics.DimsSelector) at ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/select.jl:13
  select(::Any, ::Union{AbstractString, Symbol}) at ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/select.jl:15
  select(::Any, ::Integer) at ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/select.jl:20
  ...
Stacktrace:
  [1] select(data::DataFrames.DataFrameColumns{DataFrame}, x::Pair{Vector{Symbol}, var"#11#12"})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/select.jl:39
  [2] (::AlgebraOfGraphics.var"#143#146"{DataFrames.DataFrameColumns{DataFrame}})(s::Pair{Vector{Symbol}, var"#11#12"})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/processing.jl:83
  [3] iterate
    @ ./generator.jl:47 [inlined]
  [4] _collect
    @ ./array.jl:744 [inlined]
  [5] collect_similar(cont::Array{Pair{Vector{Symbol}, var"#11#12"}, 0}, itr::Base.Generator{Array{Pair{Vector{Symbol}, var"#11#12"}, 0}, AlgebraOfGraphics.var"#143#146"{DataFrames.DataFrameColumns{DataFrame}}})
    @ Base ./array.jl:653
  [6] map(f::Function, A::Array{Pair{Vector{Symbol}, var"#11#12"}, 0})
    @ Base ./abstractarray.jl:2849
  [7] getlabeledarray(layer::Layer, s::Pair{Vector{Symbol}, var"#11#12"})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/processing.jl:82
  [8] (::AlgebraOfGraphics.var"#148#150"{Layer})(v::Pair{Vector{Symbol}, var"#11#12"})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/processing.jl:99
  [9] map!(f::AlgebraOfGraphics.var"#148#150"{Layer}, out::Dictionaries.Dictionary{Symbol, Tuple{Any, Any}}, d::Dictionaries.Dictionary{Symbol, Any})
    @ Dictionaries ~/.julia/packages/Dictionaries/zo9We/src/map.jl:57
 [10] map(f::Function, d::Dictionaries.Dictionary{Symbol, Any})
    @ Dictionaries ~/.julia/packages/Dictionaries/zo9We/src/map.jl:92
 [11] process_mappings(layer::Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/processing.jl:99
 [12] ProcessedLayer(layer::Layer)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layer.jl:61
 [13] iterate
    @ ./generator.jl:47 [inlined]
 [14] collect(itr::Base.Generator{AlgebraOfGraphics.Layers, Type{ProcessedLayer}})
    @ Base ./array.jl:724
 [15] map
    @ ./abstractarray.jl:2878 [inlined]
 [16] compute_axes_grid(s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layers.jl:130
 [17] compute_axes_grid(fig::Figure, s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/algebra/layers.jl:117
 [18] #226
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:21 [inlined]
 [19] update
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:10 [inlined]
 [20] plot!(fig::Figure, s::Layer; axis::NamedTuple{(), Tuple{}}, palettes::NamedTuple{(), Tuple{}})
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:21
 [21] (::AlgebraOfGraphics.var"#230#231"{NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, NamedTuple{(), Tuple{}}, Layer})(f::Figure)
    @ AlgebraOfGraphics ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:46
 [22] update
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:10 [inlined]
 [23] #draw#229
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:45 [inlined]
 [24] draw
    @ ~/.julia/packages/AlgebraOfGraphics/8WZVt/src/draw.jl:45 [inlined]
 [25] |>(x::Layer, f::typeof(draw))
    @ Base ./operators.jl:966
 [26] top-level scope
    @ REPL[49]:1

Steps to reproduce

Describe a sequence of steps to reproduce the behavior, ideally in the form of a
self-contained, copy-pasteable block of code.
This code should not depend on external variables available in your session and
should minimize the use of external packages.
If possible, use dummy inline data, e.g.df = (x=[1, 2], y=[3, 4], c=["a", "b"]),
instead of attaching a file with the dataset you were using when the problem occurred.

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) i9-9900K CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8
(@v1.7) pkg> status
      Status `~/.julia/environments/v1.7/Project.toml`
  [cbdf2221] AlgebraOfGraphics v0.6.5
  [336ed68f] CSV v0.10.2
  [052768ef] CUDA v3.8.2
  [13f3f980] CairoMakie v0.7.4
  [a93c6f00] DataFrames v1.3.2
  [4e90bd87] DiceRolls v0.2.0
  [587475ba] Flux v0.12.9
  [e9467ef8] GLMakie v0.5.4
  [682c06a0] JSON v0.21.3
  [0f8b85d8] JSON3 v1.9.2
  [961ee093] ModelingToolkit v8.5.1
  [429524aa] Optim v1.6.1
  [91a5bcdd] Plots v1.25.11
  [c3e4b0f8] Pluto v0.18.1
  [1a8c2f83] Query v1.0.0
  [ce6b1742] RDatasets v0.7.7
  [295af30f] Revise v3.3.2
  [856f2bd8] StructTypes v1.8.1
  [bd369af6] Tables v1.6.1
  [b8865327] UnicodePlots v2.9.0

@rongcuid
Copy link
Author

Note that the selector works for select:

julia> select(df1, [:c, :d] => (c, d) -> collect(zip(c, d)))
2×1 DataFrame
 Row │ c_d_function 
     │ Tuple…       
─────┼──────────────
   1 │ ("x", "z")
   2 │ ("y", "w")

@hendri54
Copy link

It works with a tuple (:a, :b) instead of a vector [:a, :b]:

mapping(:a, :b, color = (:c, :d) => (c, d) -> collect(zip(c, d)))

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