diff --git a/src/dataarray.jl b/src/dataarray.jl index 59b5abe..1a798b2 100644 --- a/src/dataarray.jl +++ b/src/dataarray.jl @@ -634,10 +634,14 @@ end #' k = hash(dv) # # TODO: Make sure this agrees with is_equals() -function Base.hash(a::AbstractDataArray) # -> UInt - h = hash(size(a)) + 1 - for i in 1:length(a) - h = hash(@compat(Int(hash(a[i]))), h) +function Base.hash(a::DataArray) # -> UInt + # hash NA pattern + h = hash(a.na) + # hash non-NA elements + i = findfirst(a.na, false) + while i > 0 + h = hash(a.data[i], h) + i = findnext(a.na, false, i+1) end return @compat UInt(h) end diff --git a/test/newtests/dataarray.jl b/test/newtests/dataarray.jl index 7827b93..b97972b 100644 --- a/test/newtests/dataarray.jl +++ b/test/newtests/dataarray.jl @@ -330,4 +330,7 @@ module TestDataArrays hash(DataArray([1, 2], falses(2))) hash(DataArray(repeat([1, 2], outer = [1, 2]), falses(2, 2))) hash(DataArray(repeat([1, 2], outer = [1, 2, 2]), falses(2, 2, 2))) + hash(@data [1, NA]) + hash(@data repeat( [1, 2, NA], outer = [1, 2])) + hash(@data repeat( [NA, NA, NA], outer = [1, 2, 2]), falses(2, 2, 2)) end