Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use three-valued logic with missing values in ==(::Tuple, ::Tuple) #24963

Merged
merged 2 commits into from
Dec 14, 2017
Merged
Changes from 1 commit
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
Next Next commit
Use three-valued logic with missing values in ==(::Tuple, ::Tuple)
For consistency with AbstractArray.
nalimilan committed Dec 7, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f40832dc2cfc2d7228ce5d9f5d8030cc0397e646
12 changes: 8 additions & 4 deletions base/tuple.jl
Original file line number Diff line number Diff line change
@@ -268,12 +268,16 @@ function ==(t1::Tuple, t2::Tuple)
if length(t1) != length(t2)
return false
end
anymissing = false
for i = 1:length(t1)
if !(t1[i] == t2[i])
return false
end
eq = (t1[i] == t2[i])
if ismissing(eq)
anymissing = true
elseif !eq
return false
end
end
return true
return anymissing ? missing : true
end

const tuplehash_seed = UInt === UInt64 ? 0x77cfa1eef01bca90 : 0xf01bca90
12 changes: 12 additions & 0 deletions test/missing.jl
Original file line number Diff line number Diff line change
@@ -222,6 +222,18 @@ end
@test Union{Int, Missing}[1] != Union{Int, Missing}[2]
end

@testset "== and != on tuples" begin
@test ismissing((1, missing) == (1, missing))
@test ismissing(("a", missing) == ("a", missing))
@test ismissing((missing,) == (missing,))
@test ismissing((missing, 2) == (1, missing))

@test ismissing((1, missing) != (1, missing))
@test ismissing(("a", missing) != ("a", missing))
@test ismissing((missing,) != (missing,))
@test ismissing((missing, 2) != (1, missing))
end

@testset "any & all" begin
@test any([true, missing])
@test any(x -> x == 1, [1, missing])