this looks a bit suspicious?
Also, the functions need to return a non-Union type.
Another method to consider:
using MappedArrays
sparsenonmissing4(A::AbstractMatrix) =
sparse(mappedarray(x->coalesce(x, zero(nonmissingtype(eltype(A)))), A))
As the saying goes: why not make it a one-liner? ![]()
This is faster than sparsenonmissing3.
Tiny issue: if the original matrix contains both zeroes and missings, then the resulting matrix will make them both structural zeroes in the sparse matrix.