Custom iterator breaks on last row of a readdlm-loaded array
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start by running the provided Julia reproducer with DelimitedFiles.readdlm and the custom Base.iterate implementation. Compare the iterator output with the expected final row, then inspect the linked Julia issue and Discourse discussion. Done means determining whether the bug belongs in DelimitedFiles.jl and documenting or testing the correct behavior.
Written by the indexing model from the issue text.
Description
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#28763
using DelimitedFiles # for readdlm
mutable struct mytbl # a custom object
source
function mytbl(csvdata::Base.GenericIOBuffer)
source = readdlm(csvdata, ',')
source = convert(Array, source[2:end,:]) # clear the headers
new(source)
end
end
Base.length(it::mytbl) = size(it.source, 1)
function Base.iterate(it::mytbl, (el, i)=(it.source[1,:], 1))
return i >= length(it) ? nothing : (el, (it.source[i + 1,:], i + 1))
end
# some sample data
TABLE_CAST = """id,height,age,name,occupation
1,10.0,1,string1,2012-06-15 00:00:00
2,10.1,2,string2,2013-06-15 01:00:00
"""
table = mytbl(IOBuffer(TABLE_CAST))
[ row for row in table ]
# Returns: last element is #undef
# Expected: the last element is the second row
[ row[1] for row in table ]
# Returns:
[1, 239486056]
# Expected: [1, 2]
[ row[2] for row in table ]
# Returns:
[10.0, 1.18e-315]
# Expected: [10.0, 10.1]
Note 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
- Dominant language
- Julia
- Stars
- 20
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaData/DelimitedFiles.jl
-
tagbot-manual
Difficulty 1/5 Under an hour Newbie friendliness 45/100
-
Missing 1.10 releaseOpen
Difficulty 4/5 3-5 days Newbie friendliness 25/100
JuliaData/DelimitedFiles.jl#32 · 7 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
JuliaData/DelimitedFiles.jl#1 · 7 comments ·
-
I/O
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in JuliaData/DelimitedFiles.jl
Similar issues
-
documentation priority: high
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
epiforecasts/BVDOutbreakSize#1260 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TuringLang/Turing.jl#2917 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Validate UserDemand return_factorPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days