StackOverflow Error when plotting DataFrame data

I’ve recently adopted Julia to analyze some sensor data recorded in a *.csv file.
I used the code shown below to plot a subset of my data, however the last code block to plot the data fails with the following error:

StackOverflowError:

Stacktrace:
[1] add_sym!(::Array{Symbol,1}, ::Char, ::NTuple{11,Symbol}) at /home/bjoern/.julia/packages/StatsPlots/6bINV/src/df.jl:181 (repeats 79984 times)

using Plots
using CSV
using DataFrames
using StatsPlots
gr()

df = CSV.read("./log_2020-09-24_19-04.csv") |> DataFrame

df |> @df begin
    plot(:t0, :d0)
end

The used data frame has a size of 142 rows × 11 columns; if needed I can supply some sample data.

If somebody encountered this error before any help would be appreciated.

Can you paste the output of

names(df)

That’s the names(df) output:

11-element Array{String,1}:
 "t0"
 "d0"
 "t1"
 "d1"
 "t2"
 "d2"
 "t3"
 "d3"
 "t4"
 "d4"
 "marker"

all columns are Float64 numbers

Ok, doesn’t help.
It seems we need a MWE (minimal working example) which reproduces the error.

You may first try to update your packages:

] up

That actually fixed it, should’ve done this beforehand, my bad…
Thanks for the quick help!

1 Like

I am glad :slight_smile:

Updating the packages didn’t actually fix it. I just thought it had, cause I switched over to a log file with simplified column headers to build a MWE.
When using a DataFrame with the same data, but the following names(df) output, the code still fails:

11-element Array{String,1}:
 "t0"
 "RPM revolutions_per_minute"
 "t1"
 "O2_B1S1 volt"
 "t2"
 "O2_B1S2 volt"
 "t3"
 "SHORT_FUEL_TRIM_1 percent"
 "t4"
 "LONG_FUEL_TRIM_1 percent"
 "marker"

This isn’t that big of a deal, but it would be nice to know what the breaking point is here.

How does the plot code look for this data frame? (as there is no column for :d0 available anymore)

:"RPM revolutions_per_minute"

instead of :d0

I don’t really understand what’s the reason for this behaviour, but replacing the blank with an _ in the csv file and using :RPM_revolutions_per_minute fixes the problem.

I can reproduce the stack overflow.
StatsPlots.add_sym! is an recursive function, so it recurses for ever (until Stack is overflown).

It can be considered a bug
So, you may, in the mean time, open an issue at
https://github.com/JuliaPlots/StatsPlots.jl/issues

The reason is, see below, that StatsPlots.parse_table_call! does not expect Symbols like Symbol(“a b”) with space in the string.

1 Like

It’s not a bug, because

:"RPM revolutions_per_minute"

is not a Symbol.

The following should work:

Symbol("RPM revolutions_per_minute")
1 Like

Ok thanks for the explanation! I think I will stick to using _ as mentioned earlier, because

Symbol("RPM revolutions_per_minute")

Throws the following error:

Cannot convert Symbol to series data for plotting

And it is yet a bug :wink:

It’s a bug in parsing of the expression in the macro code of @ df :

It can be seen here:

julia> e = Meta.parse("@df begin
           plot(:t0, Symbol(\"RPM revolutions_per_minute\"))
       end")
:(#= none:1 =# @df begin
          #= none:2 =#
          plot(:t0, Symbol("RPM revolutions_per_minute"))
      end)

julia> dump(e)
Expr
  head: Symbol macrocall
  args: Array{Any}((3,))
    1: Symbol @df
    2: LineNumberNode
      line: Int64 1
      file: Symbol none
    3: Expr
      head: Symbol block
      args: Array{Any}((2,))
        1: LineNumberNode
          line: Int64 2
          file: Symbol none
        2: Expr
          head: Symbol call
          args: Array{Any}((3,))
            1: Symbol plot
            2: QuoteNode
              value: Symbol t0
            3: Expr
              head: Symbol call
              args: Array{Any}((2,))
                1: Symbol Symbol
                2: String "RPM revolutions_per_minute"

As you can see, the Symbol :t0 is represented as

value: Symbol t0

But Symbol(“RPM revolutions_per_minute”) is represented as

Array{Any}((2,))
     1: Symbol Symbol
     2: String "RPM revolutions_per_minute"

This case is not taken into account in StatsPlots.parse_table_call!

Do you mind opening an issue under above link? You may refer to this discussion.

Use cols instead of Symbol to work with strings.

This causes the StackOverflow Error as well

Yes, I will open an issue. Thanks again for your help!

1 Like