queryverse / CSVFiles.jl

FileIO.jl integration for CSV files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Method error when using keywords

kescobo opened this issue · comments

I have a file that doesn't have a header, but can't seem to sort out how to load it:

julia> df = load("teststream.tsv", '\t', header=false) |> DataFrame
ERROR: MethodError: no method matching _csvread_internal(::String, ::Char; filename="teststream.tsv", header=false)
Closest candidates are:
  _csvread_internal(::AbstractString, ::Any; spacedelim, quotechar, escapechar, pooledstrings, noresize, rowno, prevheaders, skiplines_begin, samecols, header_exists, nastrings, colnames, colspool, nrows, prev_parsers, colparsers, filename, type_detect_rows) at /n/home09/kbonham/.julia/v0.6/TextParse/src/csv.jl:163 got unsupported keyword argument "header"
  _csvread_internal(::AbstractString) at /n/home09/kbonham/.julia/v0.6/TextParse/src/csv.jl:163 got unsupported keyword arguments "filename", "header"
Stacktrace:
 [1] (::TextParse.#kw##_csvread_internal)(::Array{Any,1}, ::TextParse.#_csvread_internal, ::String, ::Char) at ./<missing>:0
 [2] (::TextParse.##31#33{Array{Any,1},String,Char})(::IOStream) at /n/home09/kbonham/.julia/v0.6/TextParse/src/csv.jl:97
 [3] open(::TextParse.##31#33{Array{Any,1},String,Char}, ::String, ::String) at ./iostream.jl:152
 [4] #_csvread_f#29(::Array{Any,1}, ::Function, ::String, ::Char) at /n/home09/kbonham/.julia/v0.6/TextParse/src/csv.jl:95
 [5] (::TextParse.#kw##_csvread_f)(::Array{Any,1}, ::TextParse.#_csvread_f, ::String, ::Char) at ./<missing>:0
 [6] #csvread#25(::Array{Any,1}, ::Function, ::String, ::Char) at /n/home09/kbonham/.julia/v0.6/TextParse/src/csv.jl:69
 [7] (::TextParse.#kw##csvread)(::Array{Any,1}, ::TextParse.#csvread, ::String, ::Char) at ./<missing>:0
 [8] getiterator(::CSVFiles.CSVFile) at /n/home09/kbonham/.julia/v0.6/CSVFiles/src/CSVFiles.jl:49
 [9] _DataFrame(::CSVFiles.CSVFile) at /n/home09/kbonham/.julia/v0.6/IterableTables/src/integrations/dataframes-missing.jl:100
 [10] DataFrames.DataFrame(::CSVFiles.CSVFile) at /n/home09/kbonham/.julia/v0.6/IterableTables/src/integrations/dataframes-missing.jl:129
 [11] |>(::CSVFiles.CSVFile, ::Type{T} where T) at ./operators.jl:862

I've also tried:

df = load("teststream.tsv", delim='\t', header=false) |> DataFrame
df = load("teststream.tsv", delim='\t', header_exists=false) |> DataFrame
df = load("teststream.tsv", header=false) |> DataFrame

and using a stream instead of a file:

df = load(Stream(format"TSV", fl), header=false) |> DataFrame
# etc

I can load the file with CSV.read("teststream.tsv", delim='\t', header=false) so I don't think it's an issue with the file itself. First 5 lines of the file are here.

julia> Pkg.status("FileIO")
 - FileIO                        0.7.0

julia> Pkg.status("CSVFiles")
 - CSVFiles                      0.5.0

julia> VERSION
v"0.6.2"

But I just checked out master for both packages and have the same problem...

delim is not a keyword argument, but a positional argument. So I would think that df = load("teststream.tsv", '\t', header_exists=false) |> DataFrame should work.

But even simpler, df = load("teststream.tsv", header_exists=false) |> DataFrame should also work, because for files ending with tsv it should automatically use \t as the delim character.

I should probably change delim to just also be a keyword argument, I've just followed the TextParse.jl pattern here, but it seems more confusing than helpful.

Derp. The one combo I didn't try. It's a bit confusing that it's header_exists in load but header in save... I can sort of see the rationale, but...

Anyway, thanks for quick response.

Yeah, I agree, I should probably go over all those names and make them more consistent.