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

Adding columns with map where new name is a variable fails #303

Open
DrChainsaw opened this issue Apr 17, 2020 · 0 comments
Open

Adding columns with map where new name is a variable fails #303

DrChainsaw opened this issue Apr 17, 2020 · 0 comments

Comments

@DrChainsaw
Copy link

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)
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

1 participant