You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to parse a CSV and convert a column that holds the sex of a person into a Nullable{Bool}
My attempts failed:
sex_parser = CustomParser(Bool) do str, i, len, opts
return (len == 0 ? Nullable{Bool}() : Nullable{Bool}(str[i] == 'M'), len == 0 ? i : i + 1)
end
I spent couple of hours reading the docs and the code, but I do not understand what the str is that the tryparsenext receives in a readcsv context, and whether my CustomParser must be aware of the delimiter symbol.
For example, consider a CSV with ';' delimiter:
123;F;6789;
124;M;6712;
125;;6716;
Is str a row and my custom parse receives pos=5, len=1 for the first row and pos=5, len=0 for the third row?
And after a successful parse in row one, do I return 6 or 7. The doc is saying "position the next token, if any, starts at", that sound like my parser needs to be aware of my delimiter!
The text was updated successfully, but these errors were encountered:
I did some sleuthing and the str appears to be multiple (if not all) rows and len always is the same very big number.
However my new custom parser fails too:
sex_parser = CustomParser(Bool) do str, i, len, opts
return (str[i] == ';' ? Nullable{Bool}(nothing) : Nullable{Bool}(str[i] == 'M'), str[i] == ';' ? i + 1: i + 2)
end
A JuliaDB loadtable call yields an error:
MethodError: no method matching isless(::TextParse.StrRange, ::TextParse.StrRange)
Closest candidates are:
isless(::Missings.Missing, ::Any) at C:\Users\Max\AppData\Local\JuliaPro-0.6.2.1\pkgs-0.6.2.1\v0.6\Missings\src\Missings.jl:74
isless(::DataValues.DataValue{Union{}}, ::Any) at C:\Users\Max\AppData\Local\JuliaPro-0.6.2.1\pkgs-0.6.2.1\v0.6\DataValues\src\scalar/core.jl:257
isless(::DataValues.DataValue{S}, ::T) where {S, T} at C:\Users\Max\AppData\Local\JuliaPro-0.6.2.1\pkgs-0.6.2.1\v0.6\DataValues\src\scalar/core.jl:251
...
cmp at .\operators.jl:303 [inlined]
cmpelts at C:\Users\Max\AppData\Local\JuliaPro-0.6.2.1\pkgs-0.6.2.1\v0.6\IndexedTables\src\columns.jl:343 [inlined]
macro expansion at C:\Users\Max\AppData\Local\JuliaPro-0.6.2.1\pkgs-0.6.2.1\v0.6\IndexedTables\src\columns.jl:363 [inlined]
....
sex_parser = CustomParser(Bool) do str, i, len, opts
return (DataValues.DataValue{Bool}(str[i] == 'M'), i + 1)
end
This inner parser is wrapped in a TextParse.NAToken(sex_parser). This way an empty field is taken care of by NAToken and I can be sure that str[i] is not empty.
I am trying to parse a CSV and convert a column that holds the sex of a person into a
Nullable{Bool}
My attempts failed:
I spent couple of hours reading the docs and the code, but I do not understand what the
str
is that thetryparsenext
receives in areadcsv
context, and whether my CustomParser must be aware of the delimiter symbol.For example, consider a CSV with ';' delimiter:
Is
str
a row and my custom parse receivespos=5, len=1
for the first row andpos=5, len=0
for the third row?And after a successful parse in row one, do I return 6 or 7. The doc is saying "position the next token, if any, starts at", that sound like my parser needs to be aware of my delimiter!
The text was updated successfully, but these errors were encountered: