@rename does not work with special symbols
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.
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?
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.
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}).