From 50ae2d8e01369cbef4595f260528cfb1ab8de5a6 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Wed, 13 Feb 2019 17:09:52 -0800 Subject: [PATCH] Handle missing values in clamp --- NEWS.md | 1 + base/math.jl | 1 + test/missing.jl | 2 ++ 3 files changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index ca6ed48b754c9..3be42c2b417b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -33,6 +33,7 @@ Standard library changes (environment, flags, working directory, etc) if `x` is the first interpolant and errors otherwise ([#24353]). * `IPAddr` subtypes now behave like scalars when used in broadcasting ([#32133]). +* `clamp` can now handle missing values ([#31066]). #### Libdl diff --git a/base/math.jl b/base/math.jl index f990f8b6282df..79d9599da5045 100644 --- a/base/math.jl +++ b/base/math.jl @@ -1083,5 +1083,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/missing.jl b/test/missing.jl index 8815daa093641..db64b3176b0cb 100644 --- a/test/missing.jl +++ b/test/missing.jl @@ -164,6 +164,8 @@ Base.one(::Type{Unit}) = 1 @test ismissing(f(missing)) end + @test ismissing(clamp(missing, 1, 2)) + for T in (Int, Float64) @test zero(Union{T, Missing}) === T(0) @test one(Union{T, Missing}) === T(1)