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 a9d32c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/dataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,11 @@ 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
h = hash(a.na)
for i in @compat eachindex(a.data)
# skip NAs (since NAs pattern is already hashed, it's ok)
if !a.na[i] h = hash(a.data[i], h) end
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 a9d32c7

Please sign in to comment.