Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing values in clamp #31066

Merged
merged 1 commit into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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