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 38d6247 commit 0d6770d
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 ([#31065]).

#### 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/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ end
clamp!(x, 1, 3)
@test x == [1.0, 1.0, 2.0, 3.0, 3.0]
end

@test ismissing(clamp(missing, 1, 2))
end

@testset "constants" begin
Expand Down

0 comments on commit 0d6770d

Please sign in to comment.