DelimitedFiles.jl
DelimitedFiles.jl copied to clipboard
readdlm cannot read only part of a stream
The following code
s = """
1 2 3
4 5 6
start_other_section
"""
d = readdlm(IOBuffer(s), Int; dims=(2,3))
Results in an error being thrown:
ERROR: at row 4, column 1 : ErrorException("file entry \"start_other_section\"
cannot be converted to Int64")) in error at error.jl:21
I assume this is being caused by readdlm continuing to read the stream beyond the declared dimensions of the array. Surely this can't be the intended behavior of readdlm with array dimensions specified. The situation above is quite common, e.g. in mesh file formats where there typically is a section containing vertices and one containing cells or faces.
This example was created using:
Julia Version 0.4.5
Commit 2ac304d (2016-03-18 00:58 UTC)
Platform Info:
System: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Xeon(R) CPU E5-1620 v3 @ 3.50GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.3
FWIW, CSV.jl can parse this correctly:
julia> f = CSV.Source(IOBuffer(s);rows=2,header=0,delim=' ')
CSV.Source: <IOBuffer>
CSV.Options:
delim: ' '
quotechar: '"'
escapechar: '\\'
null: ""
dateformat: Base.Dates.DateFormat(Base.Dates.Slot[],"","english")
2x3 Data.Schema:
Column1, Column2, Column3
Int64, Int64, Int64
julia> r = Data.stream!(f, Data.Table)
Data.Table:
2x3 Data.Schema:
Column1, Column2, Column3
Int64, Int64, Int64
NullableArrays.NullableArray{T,1}[NullableArrays.NullableArray{Int64,1}[1,4],NullableArrays.NullableArray{Int64,1}[2,5],NullableArrays.NullableArray{Int64,1}[3,6]]