Error from conversion of missing values to NaNs

Because NaN is exclusively a floating-point value — you can’t store that in an integer array.

If you have a Vector{Int32}, then it is stored in memory as a sequence of consecutive 32-bit signed integer (Int32) values. Every possible bit pattern of an Int32 represents some integer — there is no bit pattern that represents a NaN without changing the type of the elements.

What you could do is

A = float(A)
A[ismissing.(A)] .= NaN

to ensure that A is a floating-point container. Or alternatively:

Anan = map(x -> ismissing(x) ? NaN : Float64(x), A)

which has the advantage that the container type of Anan will be concretely Vector{Float64}, not Vector{Union{Float64,Missing}} — the compiler will know that it can no longer contain missing values and optimize accordingly.

PS. Please quote your code: PSA: how to quote code with backticks

3 Likes