You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to plot this CSV dataset using StatsPlots.@df. I wrote and ran the following code in a fresh Pluto notebook:
using Downloads, CSV, DataFrames, StatsPlots
lifesat = CSV.read(Downloads.download("https://github.com/ageron/data/raw/main/lifesat/lifesat.csv"), DataFrame)
@df lifesat plot(cols("GDP per capita (USD)"), cols("Life satisfaction"))
I expected this to work, as per the README, but I was instead greeted by a StackOverflowError. Running again line-by-line in the Julia REPL yielded this stack trace:
And sure enough, attempting to call that first function extract_columns_and_names with those arguments yields the same error. The culprit is the following line of code in that function:
Which delegates to add_sym!, which recurses indefinitely over the first character of the first string, as follows:
add_sym!(Symbol[], "GDP per capita (USD)", (:Country, Symbol("GDP per capita (USD)"), Symbol("Life satisfaction")))
add_sym!(Symbol[], 'G', (:Country, Symbol("GDP per capita (USD)"), Symbol("Life satisfaction")))
add_sym!(Symbol[], 'G', (:Country, Symbol("GDP per capita (USD)"), Symbol("Life satisfaction")))
add_sym!(Symbol[], 'G', (:Country, Symbol("GDP per capita (USD)"), Symbol("Life satisfaction")))
# ...
The solution is to special-case strings in the definition for add_sym!, making sure not to iterate over their characters individually, but instead to convert them to symbols first.
The text was updated successfully, but these errors were encountered:
ron-wolf
changed the title
StackOverflowError when
@df: Passing column name as string overflows stack
Oct 23, 2024
FixesJuliaPlots#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.
I was trying to plot this CSV dataset using
StatsPlots.@df
. I wrote and ran the following code in a fresh Pluto notebook:I expected this to work, as per the
README
, but I was instead greeted by aStackOverflowError
. Running again line-by-line in the Julia REPL yielded this stack trace:However, this isn't the whole story, as expanding the macro by itself with
macroexpand
yields the following code (cleaned up):And sure enough, attempting to call that first function
extract_columns_and_names
with those arguments yields the same error. The culprit is the following line of code in that function:StatsPlots.jl/src/df.jl
Line 222 in bb65b7c
Which delegates to
add_sym!
, which recurses indefinitely over the first character of the first string, as follows:The solution is to special-case strings in the definition for
add_sym!
, making sure not to iterate over their characters individually, but instead to convert them to symbols first.The text was updated successfully, but these errors were encountered: