Skip to content

Commit 2ae06fe

Browse files
committed
fix rows
1 parent 793704e commit 2ae06fe

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/rows.jl

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# no automatic type inference is done, but types are allowed to be passed
33
# for as many columns as desired; `CSV.detect(row, i)` can also be used to
44
# use the same inference logic used in `CSV.File` for determing a cell's typed value
5-
struct Rows{transpose, O, IO, T}
5+
struct Rows{transpose, O, IO, T, F}
66
name::String
77
names::Vector{Symbol} # only includes "select"ed columns
88
finaltypes::Vector{Type} # only includes "select"ed columns
@@ -22,6 +22,8 @@ struct Rows{transpose, O, IO, T}
2222
positions::Vector{Int64}
2323
reusebuffer::Bool
2424
tapes::Vector{AbstractVector}
25+
filter::F
26+
codes::Vector{Int16}
2527
lookup::Dict{Symbol, Int}
2628
end
2729

@@ -99,6 +101,7 @@ function Rows(source;
99101
ignoreemptylines::Bool=false,
100102
select=nothing,
101103
drop=nothing,
104+
filter=nothing,
102105
# parsing options
103106
missingstrings=String[],
104107
missingstring="",
@@ -135,7 +138,8 @@ function Rows(source;
135138
deleteat!(finaltypes, h.todrop)
136139
deleteat!(columnmap, h.todrop)
137140
lookup = Dict(nm=>i for (i, nm) in enumerate(h.names))
138-
return Rows{transpose, typeof(h.options), typeof(h.buf), typeof(h.customtypes)}(
141+
codes = filter === nothing ? EMPTY_CODES : zeros(Int16, h.cols)
142+
return Rows{transpose, typeof(h.options), typeof(h.buf), typeof(h.customtypes), typeof(filter)}(
139143
h.name,
140144
h.names,
141145
finaltypes,
@@ -155,6 +159,8 @@ function Rows(source;
155159
h.positions,
156160
reusebuffer,
157161
tapes,
162+
filter,
163+
codes,
158164
lookup,
159165
)
160166
end
@@ -172,7 +178,7 @@ const EMPTY_REFS = RefPool[]
172178
(pos > len || row > r.limit) && return nothing
173179
pos > len && return nothing
174180
tapes = r.reusebuffer ? r.tapes : allocate(1, r.cols, r.types, r.flags)
175-
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)
181+
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)
176182
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)
177183
end
178184

0 commit comments

Comments
 (0)