Skip to content

Commit dbb6f49

Browse files
committed
Better fix
1 parent a2adce0 commit dbb6f49

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

base/reducedim.jl

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,9 @@ for (f1, f2, initval, typeextreme) in ((:min, :max, :Inf, :typemax), (:max, :min
150150
if v0 isa Number && isnan(v0)
151151
# v0 is NaN
152152
v0 = oftype(v0, $initval)
153-
elseif ismissing(v0)
154-
if !all(ismissing, A)
155-
v0 = mapreduce(f, $f2, skipmissing(A))
156-
end
157-
elseif isunordered(v0) # v0 is a third-party unordered value
158-
Tnm = nonmissingtype(Tr)
159-
# TODO: Some types, like BigInt, don't support typemin/typemax.
160-
# So a Matrix{Union{BigInt, T}} can still error here.
161-
v0 = $typeextreme(Tnm)
153+
elseif isunordered(v0) && !all(isunordered, A1)
154+
# v0 is missing or a third-party unordered value
155+
v0 = mapreduce(f, $f2, Iterators.filter(!isunordered, A1))
162156
end
163157
# v0 may have changed type.
164158
Tr = v0 isa T ? T : typeof(v0)
@@ -189,12 +183,11 @@ function reducedim_init(f::ExtremaMap, op::typeof(_extrema_rf), A::AbstractArray
189183

190184
# but NaNs and missing need to be avoided as initial values
191185
if v0[1] isa Number && isnan(v0[1])
186+
# v0 is NaN
192187
v0 = oftype(v0[1], Inf), oftype(v0[2], -Inf)
193-
elseif isunordered(v0[1])
188+
elseif isunordered(v0[1]) && !all(isunordered, A1)
194189
# v0 is missing or a third-party unordered value
195-
# TODO: Some types, like BigInt, don't support typemin/typemax.
196-
# So a Matrix{Union{BigInt, Missing}} can still error here.
197-
v0 = typemax(nonmissingtype(Tmin)), typemin(nonmissingtype(Tmax))
190+
v0 = reverse(mapreduce(f, op, Iterators.filter(!isunordered, A1)))
198191
end
199192
# v0 may have changed type.
200193
Tmin = v0[1] isa T ? T : typeof(v0[1])

test/reduce.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,6 @@ end
377377
@test maximum(Vector(Int16(1):Int16(100))) === Int16(100)
378378
@test maximum(Int32[1,2]) === Int32(2)
379379

380-
@testset "minimum/maximum over dims with missing (#35308)" begin
381-
for T in (Int, Float64, BigInt, BigFloat)
382-
x = Union{T, Missing}[1 missing; 2 missing]
383-
@test isequal(minimum(x, dims=1), reshape([1, missing], 1, :))
384-
@test isequal(maximum(x, dims=1), reshape([2, missing], 1, :))
385-
@test isequal(minimum(x, dims=2), reshape([missing, missing], :, 1))
386-
@test isequal(maximum(x, dims=2), reshape([missing, missing], :, 1))
387-
end
388-
end
389-
390380
A = circshift(reshape(1:24,2,3,4), (0,1,1))
391381
@test extrema(A,dims=1) == reshape([(23,24),(19,20),(21,22),(5,6),(1,2),(3,4),(11,12),(7,8),(9,10),(17,18),(13,14),(15,16)],1,3,4)
392382
@test extrema(A,dims=2) == reshape([(19,23),(20,24),(1,5),(2,6),(7,11),(8,12),(13,17),(14,18)],2,1,4)

test/reducedim.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ end
608608
end
609609
@testset "NaN/missing test for extrema with dims #43599" begin
610610
for sz = (3, 10, 100)
611-
for T in (Int, Float64, BigFloat)
611+
for T in (Int, Float64, BigFloat, BigInt)
612612
Aₘ = Matrix{Union{T, Missing}}(rand(-sz:sz, sz, sz))
613613
Aₘ[rand(1:sz*sz, sz)] .= missing
614614
unordered_test_for_extrema(Aₘ)
@@ -622,9 +622,16 @@ end
622622
end
623623
end
624624
end
625-
@test_broken minimum([missing;BigInt(1)], dims = 1)
626-
@test_broken maximum([missing;BigInt(1)], dims = 1)
627-
@test_broken extrema([missing;BigInt(1)], dims = 1)
625+
626+
@testset "minimum/maximum over dims with missing (#35308)" begin
627+
for T in (Int, Float64, BigInt, BigFloat)
628+
x = Union{T, Missing}[1 missing; 2 missing]
629+
@test isequal(minimum(x, dims=1), reshape([1, missing], 1, :))
630+
@test isequal(maximum(x, dims=1), reshape([2, missing], 1, :))
631+
@test isequal(minimum(x, dims=2), reshape([missing, missing], :, 1))
632+
@test isequal(maximum(x, dims=2), reshape([missing, missing], :, 1))
633+
end
634+
end
628635

629636
# issue #26709
630637
@testset "dimensional reduce with custom non-bitstype types" begin

0 commit comments

Comments
 (0)