Nothings to Missings, Any to Float with Passmissing and Parse

Hi,

I have been stumped on how to convert a Any with nothing to a Float64 with missing.

The data I am importing from BigQuery using gbq_query. The returned NULLS are as blank.

image

I try the normal passmissing parse method:

df_transformed = @chain df_raw begin
    @transform(
        :avg_theoretical_mrr = passmissing(parse).(Float64, :avg_theoretical_mrr)
        )
    end

but get the error:

ERROR: MethodError: no method matching parse(::Type{Float64}, ::Nothing)

Since nothing is not missing

I figured I would replace nothing with missing:

df_transformed.avg_theoretical_mrr = replace.(df_transformed.avg_theoretical_mrr, nothing => missing)

but get the error:
ERROR: MethodError: no method matching similar(::Missing, ::Type{Any})

I even tried to switch these to strings but this merely switched nothing to “nothing” and it won’t allow me to replace “nothing” with missing in a string… :joy:

But here is the question: is there an easy way to take type Any with blanks and convert them to Floats with missing succinctly?

Try something.(data, missing), this should return missing if a value is nothing and the value otherwise, and the result should be properly contained in a Vector{Union{Float64, Nothing}} because of the broadcasting operation.

3 Likes

Would have never thought to use something :raised_hands:
Thanks!