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

RFC: Throw an error when coalesce is passed only nothing/missing arguments #27157

Closed
wants to merge 3 commits into from

Conversation

nalimilan
Copy link
Member

@nalimilan nalimilan commented May 18, 2018

Remove the one-argument method, which does not allow passing a replacement value which can never be nothing/missing. The old behavior can still be obtained by passing Some(nothing)/Some(missing) as last argument.

Possible fix for #26927.

The advantage of this PR is that it implements a strict subset of the previous behavior. So if we change our minds and decide to allow returning nothing/missing when all arguments are nothing/missing (as in SQL and dplyr), it won't break anything.

EDIT: instead of throwing an error, we could first print a deprecation.

EDIT2: the last commit also implements the proposal made by @Keno at #26927, i.e. when nothing and missing are mixed only the first one is replaced, and the other is considered as non missing and therefore returned as-is.

@nalimilan nalimilan added the missing data Base.missing and related functionality label May 18, 2018
base/some.jl Outdated
for T in (:Nothing, :Missing)
@eval begin
coalesce(x::$T, y::Union{Nothing, Missing}) =
throw(ArgumentError("coalesce requires that least one argument differs from `nothing` or `missing`; " *
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line here is pretty long. I'd suggest changing the semicolon to a period and the space after it to a newline. Not a big deal though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fast! I wasn't sure what's the convention about this. It's indeed problematic in the doctest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Remove the one-argument method, which does not allow passing a replacement
value which can never be nothing/missing. The old behavior can still be obtained
by passing Some(nothing)/Some(missing) as last argument.

Also add a tests for recursively wrapped values like Some(Some(1)), and remove
useless 'using Base: coalesce' statements (from the time when it was not exported).
nalimilan added 2 commits May 19, 2018 22:33
Used in one place in Base, and it's the only way of unwrapping Some.
@bkamins
Copy link
Member

bkamins commented May 20, 2018

If this PR is merged I would recommend to update documentation of Some in this PR and clearly state that it is used also as a wrapper type for missing (not only nothing).

@nalimilan nalimilan added the triage This should be discussed on a triage call label May 24, 2018
@JeffBezanson
Copy link
Member

I think this is going in the right direction, but it seems really weird to me that coalesce(missing, missing) is an error, but coalesce(nothing, missing) is totally fine. The latter call is much harder to make sense of.

@JeffBezanson JeffBezanson removed the triage This should be discussed on a triage call label May 28, 2018
@ararslan ararslan deleted the nl/coalesce branch May 28, 2018 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing data Base.missing and related functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants