Skip to content

Commit

Permalink
Handle missing values in clamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Feb 14, 2019
1 parent 111b385 commit 0513b19
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([#31066]).

#### LinearAlgebra

Expand Down
1 change: 1 addition & 0 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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)
Expand Down

0 comments on commit 0513b19

Please sign in to comment.