From e75c77794019690050170e91f43a781b27842081 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Mon, 10 Jun 2019 22:21:09 -0400 Subject: [PATCH] Handle missing values in clamp (#31066) --- 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 a019289d51449..599ab62744ea9 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)