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

Symbol Causes Trouble in @transform! #330

Closed
ParadaCarleton opened this issue Jun 1, 2022 · 1 comment
Closed

Symbol Causes Trouble in @transform! #330

ParadaCarleton opened this issue Jun 1, 2022 · 1 comment

Comments

@ParadaCarleton
Copy link

It looks like when I try to use Symbol(x) to represent a column in transform, it causes trouble, e.g.

julia> @transform!(post_cycles, :residuals=:two_party_vote - Symbol("50.0%"))
ERROR: MethodError: no method matching -(::Vector{Float64}, ::Symbol)
Closest candidates are:
  -(::Array, ::SparseArrays.AbstractSparseMatrixCSC) at /usr/share/julia/stdlib/v1.7/SparseArrays/src/sparsematrix.jl:1777
  -(::Array{T, N}, ::FillArrays.Zeros{V, N}) where {T, V, N} at ~/.julia/packages/FillArrays/5Arin/src/fillalgebra.jl:241
  -(::ChainRulesCore.AbstractThunk, ::Any) at ~/.julia/packages/ChainRulesCore/GUvJT/src/tangent_types/thunks.jl:30
  ...
Stacktrace:
  [1] (::var"#83#84")(506::Vector{Float64})
    @ Main ~/.julia/packages/DataFramesMeta/kWkhX/src/parsing.jl:272
  [2] _transformation_helper(df::DataFrame, col_idx::Int64, ::Base.RefValue{Any})
    @ DataFrames ~/.julia/packages/DataFrames/zqFGs/src/abstractdataframe/selection.jl:538
  [3] select_transform!(::Base.RefValue{Any}, df::DataFrame, newdf::DataFrame, transformed_cols::Set{Symbol}, copycols::Bool, allow_resizing_newdf::Base.RefValue{Bool}, column_to_copy::BitVector)
    @ DataFrames ~/.julia/packages/DataFrames/zqFGs/src/abstractdataframe/selection.jl:764

After renaming the column and using :median, it works fine.

@pdeffebach
Copy link
Collaborator

pdeffebach commented Jun 1, 2022

Yes. That is expected. To refer to a column programatically, you should escape with $, i.e. Symbol doesn't cut it.

@transform!(post_cycles, :residuals=:two_party_vote - $(Symbol("50.0%")))

but you can use strings directly here.

@transform!(post_cycles, :residuals=:two_party_vote - $"50.0%")

PS, you can also omit the parentheses if you want

@transform! post_cycles :residuals=:two_party_vote - $"50.0%"

and ensure it's row-wise

@rtransform! post_cycles :residuals=:two_party_vote - $"50.0%"

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