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

Commit d4fdfbc

Browse files
committed
allow hashing DataArrays with NA values
1 parent b5d39c3 commit d4fdfbc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/dataarray.jl

+8-4
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,14 @@ end
634634
#' k = hash(dv)
635635
#
636636
# TODO: Make sure this agrees with is_equals()
637-
function Base.hash(a::AbstractDataArray) # -> UInt
638-
h = hash(size(a)) + 1
639-
for i in 1:length(a)
640-
h = hash(@compat(Int(hash(a[i]))), h)
637+
function Base.hash(a::DataArray) # -> UInt
638+
# hash NA pattern
639+
h = hash(a.na)
640+
# hash non-NA elements
641+
i = findfirst(a.na, false)
642+
while i > 0
643+
h = hash(a.data[i], h)
644+
i = findnext(a.na, false, i+1)
641645
end
642646
return @compat UInt(h)
643647
end

test/newtests/dataarray.jl

+3
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,7 @@ module TestDataArrays
330330
hash(DataArray([1, 2], falses(2)))
331331
hash(DataArray(repeat([1, 2], outer = [1, 2]), falses(2, 2)))
332332
hash(DataArray(repeat([1, 2], outer = [1, 2, 2]), falses(2, 2, 2)))
333+
hash(@data [1, NA])
334+
hash(@data repeat( [1, 2, NA], outer = [1, 2]))
335+
hash(@data repeat( [NA, NA, NA], outer = [1, 2, 2]), falses(2, 2, 2))
333336
end

0 commit comments

Comments
 (0)