diff --git a/src/dataarray.jl b/src/dataarray.jl index e7bdcacbc..e36f5141a 100644 --- a/src/dataarray.jl +++ b/src/dataarray.jl @@ -22,12 +22,22 @@ type DataArray{T, N} <: AbstractDataArray{T, N} data::Array{T, N} na::BitArray{N} - # Ensure data values and missingness metadata match function DataArray(d::Array{T, N}, m::BitArray{N}) + # Ensure data values and missingness metadata match if size(d) != size(m) msg = "Data and missingness arrays must be the same size" throw(ArgumentError(msg)) end + # additionally check that d does not contain NA entries + if eltype(d) === Any + for i in eachindex(d) + if isassigned(d, i) && isna(d, i) + m[i] = true + end + end + elseif eltype(d) <: NAtype + m = trues(m) + end new(d, m) end end diff --git a/test/dataarray.jl b/test/dataarray.jl index 677fe5786..ec771e5b6 100644 --- a/test/dataarray.jl +++ b/test/dataarray.jl @@ -27,6 +27,9 @@ module TestDataArray similar(dm, 2, 2) similar(dt, 2, 2, 2) + @test isequal(DataArray([NA, NA], [true, true]), DataArray([NA, NA], [false, false])) + @test isequal(DataArray(Any[1, NA], [false, true]), DataArray(Any[1, NA], [false, false])) + @test isequal(DataArray(Any[1, 2], [false, true]), DataArray(Any[1, NA], [false, false])) x = DataArray([9, 9, 8]) y = DataArray([1, 9, 3, 2, 2])