diff --git a/src/rows.jl b/src/rows.jl index 77e84d27..a008f1fd 100644 --- a/src/rows.jl +++ b/src/rows.jl @@ -2,7 +2,7 @@ # no automatic type inference is done, but types are allowed to be passed # for as many columns as desired; `CSV.detect(row, i)` can also be used to # use the same inference logic used in `CSV.File` for determing a cell's typed value -struct Rows{transpose, O, IO, T} +struct Rows{transpose, O, IO, T, F} name::String names::Vector{Symbol} # only includes "select"ed columns finaltypes::Vector{Type} # only includes "select"ed columns @@ -22,6 +22,8 @@ struct Rows{transpose, O, IO, T} positions::Vector{Int64} reusebuffer::Bool tapes::Vector{AbstractVector} + filter::F + codes::Vector{Int16} lookup::Dict{Symbol, Int} end @@ -99,6 +101,7 @@ function Rows(source; ignoreemptylines::Bool=false, select=nothing, drop=nothing, + filter=nothing, # parsing options missingstrings=String[], missingstring="", @@ -135,7 +138,8 @@ function Rows(source; deleteat!(finaltypes, h.todrop) deleteat!(columnmap, h.todrop) lookup = Dict(nm=>i for (i, nm) in enumerate(h.names)) - return Rows{transpose, typeof(h.options), typeof(h.buf), typeof(h.customtypes)}( + codes = filter === nothing ? EMPTY_CODES : zeros(Int16, h.cols) + return Rows{transpose, typeof(h.options), typeof(h.buf), typeof(h.customtypes), typeof(filter)}( h.name, h.names, finaltypes, @@ -155,6 +159,8 @@ function Rows(source; h.positions, reusebuffer, tapes, + filter, + codes, lookup, ) end @@ -172,7 +178,7 @@ const EMPTY_REFS = RefPool[] (pos > len || row > r.limit) && return nothing pos > len && return nothing tapes = r.reusebuffer ? r.tapes : allocate(1, r.cols, r.types, r.flags) - pos = parserow(1, Val(transpose), r.cols, EMPTY_TYPEMAP, tapes, r.datapos, r.buf, pos, len, r.positions, 0.0, EMPTY_REFS, 1, r.datarow + row - 2, r.types, r.flags, false, r.options, r.coloptions, r.customtypes) + pos = parserow(1, Val(transpose), r.cols, EMPTY_TYPEMAP, tapes, r.datapos, r.buf, pos, len, r.positions, 0.0, EMPTY_REFS, 1, r.datarow + row - 2, r.types, r.flags, r.filter, r.names, r.codes, false, r.options, r.coloptions, r.customtypes) return Row2(r.names, r.finaltypes, r.columnmap, r.types, r.lookup, tapes, r.buf, r.e, r.options, r.coloptions), (pos, len, row + 1) end