Skip to content

Commit 0513b19

Browse files
committed
Handle missing values in clamp
1 parent 111b385 commit 0513b19

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
@@ -38,6 +38,7 @@ Standard library changes
3838
* `hasmethod` can now check for matching keyword argument names ([#30712]).
3939
* `startswith` and `endswith` now accept a `Regex` for the second argument ([#29790]).
4040
* `retry` supports arbitrary callable objects ([#30382]).
41+
* `clamp` can now handle missing values ([#31066]).
4142

4243
#### LinearAlgebra
4344

base/math.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,5 +1070,6 @@ for f in (:(acos), :(acosh), :(asin), :(asinh), :(atan), :(atanh),
10701070
:(log2), :(exponent), :(sqrt))
10711071
@eval $(f)(::Missing) = missing
10721072
end
1073+
clamp(::Missing, lo, hi) = missing
10731074

10741075
end # module

test/missing.jl

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

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

0 commit comments

Comments
 (0)