diff --git a/Project.toml b/Project.toml index f377285a4..f5eca4884 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Compat" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.31.0" +version = "3.31.1" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/README.md b/README.md index 1512d5f5c..62f23b5d2 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ changes in `julia`. ## Supported features +* Two argument methods `findmax(f, domain)`, `argmax(f, domain)` and the corresponding `min` versions ([#35316], [#41076]) (since Compat 3.31.1) + +* `isunordered(x)` returns true if `x` is value that is normally unordered, such as `NaN` or `missing` ([#35316]) (since Compat 3.31.1) + * `get` accepts tuples and numbers ([#41007], [#41032]) (since Compat 3.31) * `muladd(A,B,z)` now accepts arrays ([#37065]) (since Compat 3.30) @@ -252,3 +256,5 @@ Note that you should specify the correct minimum version for `Compat` in the [#37065]: https://github.com/JuliaLang/julia/pull/37065 [#41007]: https://github.com/JuliaLang/julia/pull/41007 [#41032]: https://github.com/JuliaLang/julia/pull/41032 +[#35316]: https://github.com/JuliaLang/julia/pull/35316 +[#41076]: https://github.com/JuliaLang/julia/pull/41076 diff --git a/src/Compat.jl b/src/Compat.jl index 95f978845..b5726826a 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -957,21 +957,23 @@ if VERSION < v"1.2.0-DEV.246" end if VERSION < v"1.7.0-DEV.119" - # Part of https://github.com/JuliaLang/julia/pull/35316 + # Part of: + # https://github.com/JuliaLang/julia/pull/35316 + # https://github.com/JuliaLang/julia/pull/41076 isunordered(x) = false isunordered(x::AbstractFloat) = isnan(x) isunordered(x::Missing) = true isgreater(x, y) = isunordered(x) || isunordered(y) ? isless(x, y) : isless(y, x) - Base.findmax(f, domain) = mapfoldl(x -> (f(x), x), _rf_findmax, domain) - _rf_findmax((fm, m), (fx, x)) = isless(fm, fx) ? (fx, x) : (fm, m) + Base.findmax(f, domain) = mapfoldl( ((k, v),) -> (f(v), k), _rf_findmax, pairs(domain) ) + _rf_findmax((fm, im), (fx, ix)) = isless(fm, fx) ? (fx, ix) : (fm, im) - Base.findmin(f, domain) = mapfoldl(x -> (f(x), x), _rf_findmin, domain) - _rf_findmin((fm, m), (fx, x)) = isgreater(fm, fx) ? (fx, x) : (fm, m) + Base.findmin(f, domain) = mapfoldl( ((k, v),) -> (f(v), k), _rf_findmin, pairs(domain) ) + _rf_findmin((fm, im), (fx, ix)) = isgreater(fm, fx) ? (fx, ix) : (fm, im) - Base.argmax(f, domain) = findmax(f, domain)[2] - Base.argmin(f, domain) = findmin(f, domain)[2] + Base.argmax(f, domain) = mapfoldl(x -> (f(x), x), _rf_findmax, domain)[2] + Base.argmin(f, domain) = mapfoldl(x -> (f(x), x), _rf_findmin, domain)[2] end # Part of: https://github.com/JuliaLang/julia/pull/36018 diff --git a/test/runtests.jl b/test/runtests.jl index 13fe0926f..8738401e2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -946,25 +946,26 @@ end end # https://github.com/JuliaLang/julia/pull/35316 +# https://github.com/JuliaLang/julia/pull/41076 @testset "2arg" begin @testset "findmin(f, domain)" begin @test findmin(-, 1:10) == (-10, 10) - @test findmin(identity, [1, 2, 3, missing]) === (missing, missing) - @test findmin(identity, [1, NaN, 3, missing]) === (missing, missing) - @test findmin(identity, [1, missing, NaN, 3]) === (missing, missing) - @test findmin(identity, [1, NaN, 3]) === (NaN, NaN) - @test findmin(identity, [1, 3, NaN]) === (NaN, NaN) - @test all(findmin(cos, 0:π/2:2π) .≈ (-1.0, π)) + @test findmin(identity, [1, 2, 3, missing]) === (missing, 4) + @test findmin(identity, [1, NaN, 3, missing]) === (missing, 4) + @test findmin(identity, [1, missing, NaN, 3]) === (missing, 2) + @test findmin(identity, [1, NaN, 3]) === (NaN, 2) + @test findmin(identity, [1, 3, NaN]) === (NaN, 3) + @test all(findmin(cos, 0:π/2:2π) .≈ (-1.0, 3)) end @testset "findmax(f, domain)" begin @test findmax(-, 1:10) == (-1, 1) - @test findmax(identity, [1, 2, 3, missing]) === (missing, missing) - @test findmax(identity, [1, NaN, 3, missing]) === (missing, missing) - @test findmax(identity, [1, missing, NaN, 3]) === (missing, missing) - @test findmax(identity, [1, NaN, 3]) === (NaN, NaN) - @test findmax(identity, [1, 3, NaN]) === (NaN, NaN) - @test findmax(cos, 0:π/2:2π) == (1.0, 0.0) + @test findmax(identity, [1, 2, 3, missing]) === (missing, 4) + @test findmax(identity, [1, NaN, 3, missing]) === (missing, 4) + @test findmax(identity, [1, missing, NaN, 3]) === (missing, 2) + @test findmax(identity, [1, NaN, 3]) === (NaN, 2) + @test findmax(identity, [1, 3, NaN]) === (NaN, 3) + @test findmax(cos, 0:π/2:2π) == (1.0, 1) end @testset "argmin(f, domain)" begin