diff --git a/NEWS.md b/NEWS.md index 71fc55d2ed251..5595fd3daa4c1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -38,6 +38,7 @@ Standard library changes * `hasmethod` can now check for matching keyword argument names ([#30712]). * `startswith` and `endswith` now accept a `Regex` for the second argument ([#29790]). * `retry` supports arbitrary callable objects ([#30382]). +* `clamp` can now handle missing values ([#31065]). #### LinearAlgebra diff --git a/base/math.jl b/base/math.jl index 4f9be26562fb6..5ba7b0a7d1c7d 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1070,5 +1070,6 @@ for f in (:(acos), :(acosh), :(asin), :(asinh), :(atan), :(atanh), :(log2), :(exponent), :(sqrt)) @eval $(f)(::Missing) = missing end +clamp(::Missing, lo, hi) = missing end # module diff --git a/test/math.jl b/test/math.jl index 9887f7c7a1289..1a8a125c3f3c5 100644 --- a/test/math.jl +++ b/test/math.jl @@ -27,6 +27,8 @@ end clamp!(x, 1, 3) @test x == [1.0, 1.0, 2.0, 3.0, 3.0] end + + @test ismissing(clamp(missing, 1, 2)) end @testset "constants" begin