JuliaData / CSV.jl

Utility library for working with CSV and other delimited files in the Julia programming language
https://csv.juliadata.org/
Other
470 stars 140 forks source link

Forcing Measurements type causes parse error #645

Closed tlnagy closed 4 years ago

tlnagy commented 4 years ago

Reading in a CSV containing Measurements.jl measurements and forcing the correct type Measurements{Float64} causes CSV.jl to throw a bunch of warnings and report all values in that column as missing.

julia> using CSV, DataFrames, Measurements

julia> df = CSV.read(IOBuffer("""A
       10.0 ± 10.0
       5.0 ± 2.0"""), types=Dict(:A => Measurement{Float64}));
thread = 1 warning: error parsing Float64 on row = 1, col = 1: "10.0 ± 10.0", error=INVALID: OK | SENTINEL | NEWLINE | INVALID_DELIMITER 
thread = 1 warning: error parsing Float64 on row = 2, col = 1: "5.0 ± 2.0", error=INVALID: OK | SENTINEL | EOF | INVALID_DELIMITER 

julia> parse(Measurement{Float64}, "10.0 ± 5.0")
10.0 ± 5.0
Environment details

```julia (@v1.4) pkg> st Status `~/.julia/environments/v1.4/Project.toml` [336ed68f] CSV v0.6.1 [a93c6f00] DataFrames v0.20.2 [eff96d63] Measurements v2.2.1 julia> versioninfo() Julia Version 1.4.2 Commit 44fa15b150* (2020-05-23 18:35 UTC) Platform Info: OS: Linux (x86_64-pc-linux-gnu) CPU: AMD Ryzen 7 2700X Eight-Core Processor WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-8.0.1 (ORCJIT, znver1) ```

quinnj commented 4 years ago

This is expected; currently CSV.jl only supports parsing a strict, standard set of types (Int, Float64, Date, DateTime, Time, Bool, String). I'm currently working through some internals refactoring to hopefully allow this kind of flexibility though (#639 )

quinnj commented 4 years ago

Closing as dup of https://github.com/JuliaData/CSV.jl/issues/431