# StackOverflow Error when plotting DataFrame data

**URL:** <https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774>\
**Category:** Visualization\
**Tags:** plotting, dataframes\
**Created:** [October 5, 2020, 9:03am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774 "2020-10-05T09:03:48Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 9:03am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/1 "2020-10-05T09:03:48Z")

</div>

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)

```julia
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.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 9:41am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/2 "2020-10-05T09:41:06Z")

</div>

Can you paste the output of

```julia
names(df)

```

---

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 9:50am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/3 "2020-10-05T09:50:58Z")

</div>

That’s the names(df) output:

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

```

all columns are Float64 numbers

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 9:57am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/4 "2020-10-05T09:57:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 10:05am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/5 "2020-10-05T10:05:10Z")

</div>

You may first try to update your packages:

```julia
] up

```

---

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 10:13am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/6 "2020-10-05T10:13:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 10:14am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/7 "2020-10-05T10:14:24Z")

</div>

I am glad 🙂

---

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 10:37am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/8 "2020-10-05T10:37:00Z")

</div>

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 10:53am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/9 "2020-10-05T10:53:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 11:00am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/10 "2020-10-05T11:00:32Z")

</div>

```julia
:"RPM revolutions_per_minute"

```

instead of :d0

---

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 11:06am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/11 "2020-10-05T11:06:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 11:09am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/12 "2020-10-05T11:09:32Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 11:23am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/13 "2020-10-05T11:23:54Z")

</div>

It’s not a bug, because

```julia
:"RPM revolutions_per_minute"

```

is not a Symbol.

The following should work:

```julia
Symbol("RPM revolutions_per_minute")

```

---

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 11:30am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/14 "2020-10-05T11:30:37Z")

</div>

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

```julia
Symbol("RPM revolutions_per_minute")

```

Throws the following error:

```julia
Cannot convert Symbol to series data for plotting

```

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [October 5, 2020, 11:44am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/15 "2020-10-05T11:44:10Z")

</div>

And it is yet a bug 😉

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

It can be seen here:

```julia
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

```julia
value: Symbol t0

```

But Symbol(“RPM revolutions\_per\_minute”) is represented as

```julia
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.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 5, 2020, 11:56am UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/16 "2020-10-05T11:56:33Z")

</div>

Use `cols` instead of `Symbol` to work with strings.

---

<div class="post-metadata">

**Author:** ![b.lind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/b.lind/32/18423_2.png) [@b.lind](https://discourse.julialang.org/u/b.lind)\
**Post date:** [October 5, 2020, 1:18pm UTC](https://discourse.julialang.org/t/stackoverflow-error-when-plotting-dataframe-data/47774/17 "2020-10-05T13:18:04Z")

</div>

> [@pdeffebach](#):
>
> Use `cols` instead of `Symbol` to work with strings.

This causes the StackOverflow Error as well

> [@oheil](#):
>
> Do you mind opening an issue under above link? You may refer to this discussion.

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