Home > Enterprise >  Julia CSV.read not recognizing "select" keyword
Julia CSV.read not recognizing "select" keyword

Time:06-02

I am reading in a space-delimited file using the CSV library in Julia.

edgeList = CSV.read(
    joinpath(dataDirectory, "out.file"),
    types=[Int, Int],
    header=["node1", "node2"],
    skipto=3,
    select=[1,2]
)

This yields the following error:

MethodError: no method matching CSV.File(::String; types=DataType[Int64, Int64], header=["node1", "node2"], skipto=3, select=[1, 2])
Closest candidates are:
  CSV.File(::Any; header, normalizenames, datarow, skipto, footerskip, limit, transpose, comment, use_mmap, ignoreemptylines, missingstrings, missingstring, delim, ignorerepeated, quotechar, openquotechar, closequotechar, escapechar, dateformat, decimal, truestrings, falsestrings, type, types, typemap, categorical, pool, strict, silencewarnings, threaded, debug, parsingdebug, allowmissing) at /Users/n.jordanjameson/.julia/packages/CSV/4GOjG/src/CSV.jl:221 got unsupported keyword argument "select"

I am using Julia v. 1.6.2. Here is the output versioninfo():

Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i7-5650U CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, broadwell)

The version of CSV is 0.10.4. The wiki for this version of CSV is here: https://csv.juliadata.org/stable/reading.html#CSV.read, and it has a select / drop entry.

The file I am trying to read is from here: http://konect.cc/networks/moreno_crime/ (the file I'm using is called "out.moreno_crime_crime"). The first few lines are:

% bip unweighted
% 1476 829 551
1 1 
1 2 
1 3 
1 4 
2 5 
2 6 
2 7 
2 8 
2 9 
2 10 

CodePudding user response:

I get a different error than you, can you restart Julia and make sure?

julia> CSV.read("/home/akako/Downloads/moreno_crime/out.moreno_crime_crime"; types=[Int, Int],
           header=["node1", "node2"],
           skipto=3,
           select=[1,2]
       )
ERROR: ArgumentError: provide a valid sink argument, like `using DataFrames; CSV.read(source, DataFrame)`
Stacktrace:
 [1] read(source::String, sink::Nothing; copycols::Bool, kwargs::Base.Pairs{Symbol, Any, NTuple{4, Symbol}, NamedTuple{(:types, :header, :skipto, :select), Tuple{Vector{DataType}, Vector{String}, Int64, Vector{Int64}}}})
   @ CSV ~/.julia/packages/CSV/jFiCn/src/CSV.jl:89
 [2] top-level scope
   @ REPL[8]:1
Stacktrace:

this error is telling you you can't CSV.read without a target sink, you might want to use CSV.File

julia> CSV.File("/home/akako/Downloads/moreno_crime/out.moreno_crime_crime"; types=[Int, Int],
           header=["node1", "node2"],
           skipto=3,
           select=[1,2]
       )
┌ Warning: thread = 1 warning: parsed expected 2 columns, but didn't reach end of line around data row: 1. Parsing extra columns and widening final columnset
└ @ CSV ~/.julia/packages/CSV/jFiCn/src/file.jl:579
1476-element CSV.File:
 CSV.Row: (node1 = 1, node2 = 1, Column3 = missing)
 CSV.Row: (node1 = 1, node2 = 2, Column3 = missing)
 CSV.Row: (node1 = 1, node2 = 3, Column3 = missing)
 CSV.Row: (node1 = 1, node2 = 4, Column3 = missing)
  • Related