From 8eaf3080b96fe4c9e9274b00ea6eee66e0a01d3e Mon Sep 17 00:00:00 2001 From: Ron Wolf Date: Wed, 23 Oct 2024 19:11:56 -0700 Subject: [PATCH] Make @df support string column names Fixes #562. Add a special case to `add_sym!` to convert an `AbstractString` column name to a `Symbol` before adding it. The old behavior would iterate over the string and try to add each character as a column name. This produced a stack overflow, since `add_sym!` had no special case for `Char`, resulting in indefinite recursion. --- src/df.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/df.jl b/src/df.jl index 8201200..a6d5e7d 100644 --- a/src/df.jl +++ b/src/df.jl @@ -191,6 +191,8 @@ get_col(syms, col_nt, names) = hcat((get_col(s, col_nt, names) for s in syms)... # get the appropriate name when passed an Integer add_sym!(cols, i::Integer, names) = push!(cols, names[i]) +# get the appropriate name when passed a string +add_sym!(cols, str::AbstractString, names) = add_sym!(cols, Symbol(str), names) # check for errors in Symbols add_sym!(cols, s::Symbol, names) = s in names ? push!(cols, s) : cols # recursively extract column names