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

Commit a9d32c7

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

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/dataarray.jl

+5-4
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,11 @@ 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+
h = hash(a.na)
639+
for i in @compat eachindex(a.data)
640+
# skip NAs (since NAs pattern is already hashed, it's ok)
641+
if !a.na[i] h = hash(a.data[i], h) end
641642
end
642643
return @compat UInt(h)
643644
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)