Skip to content

Commit

Permalink
Ensure dropped columns have type set as missing (#943)
Browse files Browse the repository at this point in the history
* Ensure dropped columns have type set as missing

Fixes #942. When dropping columns while parsing via `select` or `drop`,
we need to ensure the column type gets set as `HardMissing`.

* finish test
  • Loading branch information
quinnj authored Nov 16, 2021
1 parent a68bb04 commit b747df8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
# but in HardMissing case, we don't; we know the column will *always* be Missing
struct HardMissing end

willdrop!(columns, i) = setfield!(@inbounds(columns[i]), :willdrop, true)
function willdrop!(columns, i)
@inbounds col = columns[i]
col.willdrop = true
col.type = HardMissing
return
end

struct NeedsTypeDetection end

Expand Down
10 changes: 10 additions & 0 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,14 @@ f = CSV.File(joinpath(dir, "multithreadedpromote.csv"))
@test eltype(f.col1) == String7
@test length(f) == 5001

# 942
data = """
name, age
Jack, 12
Tom, 10
"""
f = CSV.File(IOBuffer(data); select=[2], type=Int32)
@test length(f) == 2
@test length(f.names) == 1

end

0 comments on commit b747df8

Please sign in to comment.