queryverse / queryverse/Query.jl

Adding columns with map where new name is a variable fails

Open
#303 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
403
Forks
48
Avg merge
3d 6h
Merged PRs (30d)
6

Description


dff = DataFrame(a=1:3, b=3:5)

#No problem with litterals:
addcol(row) = merge(row, (;:c => 1))

dff |> @map(addcol(_)) |> DataFrame

# But this fails:
addcol(row, cname) = merge(row, (;cname => 1))

dff |> @map(addcol(_, :c)) |> DataFrame
ERROR: MethodError: no method matching nondatavaluenamedtuple(::Type{NamedTuple})
Closest candidates are:
  nondatavaluenamedtuple(::Type{NT}) where {names, NT<:(NamedTuple{names,T} where T<:Tuple)} at C:\Users\echrska\.julia\packages\Tables\okt7x\src\tofromdatavalues.jl:2
Stacktrace:
 [1] schema(::Tables.IteratorWrapper{QueryOperators.EnumerableMap{NamedTuple,QueryOperators.EnumerableIterable{NamedTuple{(:a,
:b),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.Schema{(:a, :b),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Int64,1}}}}}},var"#290#292"}}) at C:\Users\echrska\.julia\packages\Tables\okt7x\src\tofromdatavalues.jl:32
 [2] columns at C:\Users\echrska\.julia\packages\Tables\okt7x\src\fallbacks.jl:237 [inlined]
 [3] DataFrame(::QueryOperators.EnumerableMap{NamedTuple,QueryOperators.EnumerableIterable{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.Schema{(:a, :b),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Int64,1}}}}}},var"#290#292"}; copycols::Bool) at C:\Users\echrska\.julia\packages\DataFrames\S3ZFo\src\other\tables.jl:40
 [4] DataFrame(::QueryOperators.EnumerableMap{NamedTuple,QueryOperators.EnumerableIterable{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.Schema{(:a, :b),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Int64,1}}}}}},var"#290#292"}) at C:\Users\echrska\.julia\packages\DataFrames\S3ZFo\src\other\tables.jl:31
 [5] |>(::QueryOperators.EnumerableMap{NamedTuple,QueryOperators.EnumerableIterable{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.Schema{(:a, :b),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Int64,1}}}}}},var"#290#292"}, ::Type{T} where T) at .\operators.jl:823
 [6] top-level scope at none:0

# This too:
@from r in dff begin
       @select addcol(r, :c)
       @collect DataFrame
       end
ERROR: MethodError: no method matching nondatavaluenamedtuple(::Type{NamedTuple})
Closest candidates are:
  nondatavaluenamedtuple(::Type{NT}) where {names, NT<:(NamedTuple{names,T} where T<:Tuple)} at C:\Users\echrska\.julia\packages\Tables\okt7x\src\tofromdatavalues.jl:2
Stacktrace:
 [1] schema(::Tables.IteratorWrapper{QueryOperators.EnumerableMap{NamedTuple,QueryOperators.EnumerableIterable{NamedTuple{(:a,
:b),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.Schema{(:a, :b),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Int64,1}}}}}},var"#297#298"}}) at C:\Users\echrska\.julia\packages\Tables\okt7x\src\tofromdatavalues.jl:32
 [2] columns at C:\Users\echrska\.julia\packages\Tables\okt7x\src\fallbacks.jl:237 [inlined]
 [3] DataFrame(::QueryOperators.EnumerableMap{NamedTuple,QueryOperators.EnumerableIterable{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.Schema{(:a, :b),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Int64,1}}}}}},var"#297#298"}; copycols::Bool) at C:\Users\echrska\.julia\packages\DataFrames\S3ZFo\src\other\tables.jl:40
 [4] DataFrame(::QueryOperators.EnumerableMap{NamedTuple,QueryOperators.EnumerableIterable{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.DataValueRowIterator{NamedTuple{(:a, :b),Tuple{Int64,Int64}},Tables.Schema{(:a, :b),Tuple{Int64,Int64}},Tables.RowIterator{NamedTuple{(:a, :b),Tuple{Array{Int64,1},Array{Int64,1}}}}}},var"#297#298"}) at C:\Users\echrska\.julia\packages\DataFrames\S3ZFo\src\other\tables.jl:31
 [5] top-level scope at none:0

# But this works:
DataFrame(@from r in dff begin
       @select addcol(r, :c)
       @collect
       end)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using @map with addcol(_, :c), then compare it with the working DataFrame(@from ... @collect) path. Trace the @map and @from/@select/@collect entry points through DataFrame conversion; done means a variable column name works in both examples without breaking the literal-name case.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.