Skip to content
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

Fix multithreaded fail on trailing empty column #1098

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/detection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,11 @@ end
function findchunkrowstart(ranges, i, buf, opts, typemap, downcast, ncols, rows_to_check, columns, origcoltypes, columnlock, @nospecialize(stringtype), totalbytes, totalrows, succeeded)
pos = ranges[i]
len = ranges[i + 1] - 1
addtrailingcolumn = false # set if the file ends with an empty column with no trailing newline
if i == length(ranges)-1
len += 1 # correctly handle the absence of a trailing newline
addtrailingcolumn = Parsers.delimited(Parsers.xparse(String, buf, len, len, opts).code)
end
nextrowpos = 0
startpos = pos
code = Parsers.ReturnCode(0)
Expand Down Expand Up @@ -394,6 +399,7 @@ function findchunkrowstart(ranges, i, buf, opts, typemap, downcast, ncols, rows_
rowsparsed += ((pos < len) | (numcolsthisrow != 0)) # trailing newline does not count
parsedncols += numcolsthisrow
end
parsedncols += addtrailingcolumn
lock(columnlock) do
for i = 1:ncols
cp = columnprops[i]
Expand Down Expand Up @@ -475,8 +481,8 @@ function findrowstarts!(buf, opts, ranges, ncols, columns, @nospecialize(stringt
while ranges[new_last_idx] > stop
new_last_idx -= 1
end
ranges[new_last_idx+1] = stop
resize!(ranges, new_last_idx+1)
ranges[end] = stop
unique!(ranges) # in case multiple tasks start on the same row
newranges = similar(ranges)
N = length(ranges) - 1
Expand Down
5 changes: 5 additions & 0 deletions test/testfiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ testfiles = [
NamedTuple{(:x, :y), Tuple{Int, Int}},
(x = [15887, 23603], y = [24651, 14076])
),
("test_trailing_empty_column.csv", (ntasks=3,),
(14,3),
NamedTuple{(:X,:Y,:Z), Tuple{Int, Union{Missing,String7}, Union{Missing,Float64}}},
nothing
)
];

@static if VERSION >= v"1.3-DEV"
Expand Down
15 changes: 15 additions & 0 deletions test/testfiles/test_trailing_empty_column.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
X,Y,Z
1,aaaa,.1
2,bbbb,.2
3,cccc,.3
4,dddd,.4
5,eeee,.5
6,ffff,.6
7,gggg,.7
8,hhhh,.8
9,iiii,.9
10,jjjj,.10
11,kkkk,.11
12,llll,.12
13,mmmm,.13
14,,