Skip to content

Commit

Permalink
Handle missing values in clamp (#31066)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored Jun 11, 2019
1 parent f1764ed commit e75c777
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 @@ -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

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

0 comments on commit e75c777

Please sign in to comment.