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

Commit

Permalink
allow hashing DataArrays with NA values
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed Jun 15, 2015
1 parent b5d39c3 commit d4fdfbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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

0 comments on commit d4fdfbc

Please sign in to comment.