DataArrays.jl icon indicating copy to clipboard operation
DataArrays.jl copied to clipboard

Cannot JSON convert data arrays with NA

Open disleyland opened this issue 8 years ago • 3 comments

cannot JSON convert any data arrays with NA.

JSON.json(@data [1,2,NA]) used to produce "[1,2,{}]" but now produces the error "Cannot serialize type DataArrays.NAtype"

guessing this is because the vector syntax {} is now discontinued

is there a workaround? or before converting do we have to manually convert all data arrays to nothing or "" ?

This issue was reported in JSON.jl.

disleyland avatar May 08 '17 08:05 disleyland

Hmm, serialization seems to work fine, so I'm not sure what's the problem. Will ask upstream.

using DataArrays
x=@data [1,2,NA]
io=IOBuffer()
serialize(io, x)
seekstart(io)
deserialize(io)

nalimilan avatar May 08 '17 10:05 nalimilan

As a workaround you can just write

try JSON.lower(NA) catch
    JSON.lower(::DataArrays.NAtype) = nothing
end

in your own code for now. This is type piracy and not a good long term solution, but the try/catch ensures that it will only add the definition if it doesn't already exist.

TotalVerb avatar May 10 '17 04:05 TotalVerb

A slightly nicer (though basically equivalent) workaround:

if !applicable(JSON.lower, NA)
    JSON.lower(::NAtype) = nothing
end

ararslan avatar Jul 05 '17 04:07 ararslan