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

Fix minimum and maximum in the presence of missing values #35989

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,11 @@ function mapreduce_impl(f, op::Union{typeof(max), typeof(min)},
start = first + 1
simdstop = start + chunk_len - 4
while simdstop <= last - 3
# short circuit in case of NaN
v1 == v1 || return v1
v2 == v2 || return v2
v3 == v3 || return v3
v4 == v4 || return v4
# short circuit in case of NaN or missing
(v1 == v1) === true || return v1
(v2 == v2) === true || return v2
(v3 == v3) === true || return v3
(v4 == v4) === true || return v4
@inbounds for i in start:4:simdstop
v1 = _fast(op, v1, f(A[i+0]))
v2 = _fast(op, v2, f(A[i+1]))
Expand Down
12 changes: 12 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@ A = circshift(reshape(1:24,2,3,4), (0,1,1))
@test size(extrema(A,dims=(1,2,3))) == size(maximum(A,dims=(1,2,3)))
@test extrema(x->div(x, 2), A, dims=(2,3)) == reshape([(0,11),(1,12)],2,1,1)

@testset "maximum/minimum/extrema with missing values" begin
for x in (Vector{Union{Int,Missing}}(missing, 10),
Vector{Union{Int,Missing}}(missing, 257))
@test maximum(x) === minimum(x) === missing
@test extrema(x) === (missing, missing)
fill!(x, 1)
x[1] = missing
@test maximum(x) === minimum(x) === missing
@test extrema(x) === (missing, missing)
end
end

# any & all

@test @inferred any([]) == false
Expand Down