Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV.Rows errors when types for a column is specified to be Symbol #929

Closed
AayushSabharwal opened this issue Oct 15, 2021 · 1 comment · Fixed by #931
Closed

CSV.Rows errors when types for a column is specified to be Symbol #929

AayushSabharwal opened this issue Oct 15, 2021 · 1 comment · Fixed by #931

Comments

@AayushSabharwal
Copy link

AayushSabharwal commented Oct 15, 2021

Consider the following sample CSV:

id,pos_1,pos_2,pos_3,has_prisoner,capture_time,shape
5,11,86,1,false,0,diamond
4,5,43,1,false,0,diamond
6,16,90,1,false,0,diamond
7,75,35,1,false,0,diamond
2,35,89,1,false,0,diamond
10,81,25,1,false,0,diamond
9,48,98,1,false,0,diamond
8,98,62,1,false,0,diamond
3,50,2,1,false,0,diamond
1,95,24,1,false,0,diamond

The last column (shape) is required to be a Symbol. Specifying this through the types keyword seems to error on 0.9.6:

julia> for r in CSV.Rows(read("test/test.csv"); types = Dict(:id => Int, :pos_1 => Int, :pos_2 => Int, :pos_3 => Int, :has_prisoner => Bool, :capture_time => Int, :shape => Symbol))
           print(r)
       end
ERROR: UndefVarError: values not defined
Stacktrace:
 [1] iterate
   @ ~/.julia/packages/CSV/owrEo/src/rows.jl:266 [inlined]
 [2] iterate(r::CSV.Rows{Vector{UInt8}, Tuple{Symbol}, Any, PosLenString})
   @ CSV ~/.julia/packages/CSV/owrEo/src/rows.jl:274
 [3] top-level scope
   @ ./REPL[4]:1

The same issue does not arise when the type for :shape is specified to be String. It seems to be specific to CSV.Rows. This does not error:

julia> CSV.File(read("test/test.csv"); types = Dict(:id => Int, :pos_1 => Int, :pos_2 => Int, :pos_3 => Int, :has_prisoner => Bool, :capture_time => Int, :shape => Symbol))

Ping JuliaDynamics/Agents.jl#550

quinnj added a commit that referenced this issue Oct 19, 2021
Fixes #929. I admit I don't fully understand what exactly is going wrong
here, but it seems that using the `@unrollcolumns` macro inside the `for
i = 1:cols` loop is somehow getting lost when it tries to reference the
`values` array from the unrolled macro block. I know there have been
various issues like this raised at JuliaLang/julia, but it's easy enough
for us to just pass in `values` an explicit argument to the macro, so
that seems an easy enough work-around for now.
@quinnj
Copy link
Member

quinnj commented Oct 19, 2021

Thanks @AayushSabharwal for the report! A fix (work-around) is up: #931

quinnj added a commit that referenced this issue Oct 19, 2021
Fixes #929. I admit I don't fully understand what exactly is going wrong
here, but it seems that using the `@unrollcolumns` macro inside the `for
i = 1:cols` loop is somehow getting lost when it tries to reference the
`values` array from the unrolled macro block. I know there have been
various issues like this raised at JuliaLang/julia, but it's easy enough
for us to just pass in `values` an explicit argument to the macro, so
that seems an easy enough work-around for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants