-
Notifications
You must be signed in to change notification settings - Fork 2
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
Custom iterator breaks on last row of a readdlm-loaded array #3
Comments
Isn't this just a faulty function Base.iterate(it::mytbl, i=1)
return i > length(it) ? nothing : (it.source[i, :], (i+1))
end we get julia> [ row for row in table ]
2-element Array{Array{Any,1},1}:
[1, 10.0, 1, "string1", "2012-06-15 00:00:00"]
[2, 10.1, 2, "string2", "2013-06-15 01:00:00"]
julia> [ row[1] for row in table ]
2-element Array{Int64,1}:
1
2
julia> [ row[2] for row in table ]
2-element Array{Float64,1}:
10.0
10.1 |
There I suppose there's two things going on here: instead of |
Maybe the array comprehension code could check that the number of collected elements matches the declared length for |
Yes, this is very similar to JuliaLang/julia#28763. Adding a check for iterating fewer than |
JuliaLang/julia#29458 catches this: julia> [ row for row in table ]
ERROR: iterator returned fewer elements than its declared length
Stacktrace:
[1] collect_to!(::Array{Array{Any,1},1}, ::Base.Generator{mytbl,getfield(Main, Symbol("##3#4"))}, ::Int64, ::Tuple{Array{Any,1},Int64}) at ./array.jl:690
[2] collect_to_with_first!(::Array{Array{Any,1},1}, ::Array{Any,1}, ::Base.Generator{mytbl,getfield(Main, Symbol("##3#4"))}, ::Tuple{Array{Any,1},Int64}) at ./array.jl:663
[3] collect(::Base.Generator{mytbl,getfield(Main, Symbol("##3#4"))}) at ./array.jl:644
[4] top-level scope at none:0
julia> [ row[1] for row in table ]
ERROR: iterator returned fewer elements than its declared length
Stacktrace:
[1] collect_to!(::Array{Int64,1}, ::Base.Generator{mytbl,getfield(Main, Symbol("##5#6"))}, ::Int64, ::Tuple{Array{Any,1},Int64}) at ./array.jl:690
[2] collect_to_with_first!(::Array{Int64,1}, ::Int64, ::Base.Generator{mytbl,getfield(Main, Symbol("##5#6"))}, ::Tuple{Array{Any,1},Int64}) at./array.jl:663
[3] collect(::Base.Generator{mytbl,getfield(Main, Symbol("##5#6"))}) at ./array.jl:644
[4] top-level scope at none:0 |
When using a custom iterator over an array created with
readdlm
, the last row is broken in Julia 1.0. Yes, I did test this with no warnings in 0.7. This behavior looks like a bug to me and possibly related to JuliaLang/julia#28763Note that I've tested this with more elements, the last row is always..well, broken.
Further discussion and a workaround in https://discourse.julialang.org/t/last-row-is-broken-when-iterating-an-array/15696
The text was updated successfully, but these errors were encountered: