Skip to content

Commit e75c777

Browse files
authored
Handle missing values in clamp (#31066)
1 parent f1764ed commit e75c777

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Standard library changes
3333
(environment, flags, working directory, etc) if `x` is the first interpolant and errors
3434
otherwise ([#24353]).
3535
* `IPAddr` subtypes now behave like scalars when used in broadcasting ([#32133]).
36+
* `clamp` can now handle missing values ([#31066]).
3637

3738
#### Libdl
3839

base/math.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,5 +1083,6 @@ for f in (:(acos), :(acosh), :(asin), :(asinh), :(atan), :(atanh),
10831083
:(log2), :(exponent), :(sqrt))
10841084
@eval $(f)(::Missing) = missing
10851085
end
1086+
clamp(::Missing, lo, hi) = missing
10861087

10871088
end # module

test/missing.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ Base.one(::Type{Unit}) = 1
164164
@test ismissing(f(missing))
165165
end
166166

167+
@test ismissing(clamp(missing, 1, 2))
168+
167169
for T in (Int, Float64)
168170
@test zero(Union{T, Missing}) === T(0)
169171
@test one(Union{T, Missing}) === T(1)

0 commit comments

Comments
 (0)