Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Allow hashing DataArrays with NA values #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/dataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/newtests/dataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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