Skip to content

@rename does not work with special symbols #258

Description

@aplavin

Due to the way @rename searches for column names, it is impossible to rename from/to names which have special characters in them. E.g. @rename(Symbol("#abc def.") => :newname) does not work.

Activity

  1. added this to the Backlog milestone on Apr 8, 2019
  2. JonasIsensee commented on May 7, 2020

    @JonasIsensee

    Just came across this.
    It's tedious to work with long (multi-word) collumn-headers that might come from reading in a csv file.
    Is there any workaround?

  3. ilyagr commented on Aug 9, 2020

    @ilyagr
    Contributor

    Is there a good workaround?

    After looking at the namedtuple.jl docstrings, the best I found so far is the following:

    df |> @map((; Symbol("Cool name")=>_.bat, _.bar)) # One direction
    df |> @map((bat = _[Symbol("Cool name")],_.bar))  # Can be a bit simpler in the other direction

    It's not pretty, and one has to explicitly list all the columns that one wants to keep.

    It also feels really strange that df |> @rename(:bar => :a) works, but df |> @rename(:bar => Symbol("a")) fails with a strange error message.

    ERROR: MethodError: no method matching getindex(::Nothing, ::Int64)
    Stacktrace:
     [1] @rename(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at /home/ilyagr/.julia/packages/Query/85Sw7/src/table_query_macros.jl:149
     [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088
    

    P.S. My use-case is not actually that I have spaces in the name, but rather that I'd like to use Symbol("best_$x") where x is a variable.

  4. ilyagr commented on Aug 9, 2020

    @ilyagr
    Contributor

    I think this also affects @select. There, the best workaround I could find was @select(startswith('Cool name')).

    I thought @select(==('Cool name')) should work, but it doesn't, reporting ERROR: MethodError: no method matching zero(::Type{Any}).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions