-
Notifications
You must be signed in to change notification settings - Fork 7
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
Should comparison operators return Bool values? #7
Comments
The whole point of having a data type for missing values is to have something that is not in base so that we can iterate faster. But if this data type is not in base, then a filter in a generator can't special case it, so there is no way to get filter expressions in a generator to drop I also just generally think that you make a system a LOT more complicated the moment you introduce 3VL. That aspect of SQL is not a strength, it makes things much more complicated. I'd also like to point out that C# had this behavior for over a decade, and there is almost no complaining about it (unlike the SQL story). Finally, I think there are a gazillion examples of how people can write functions where they didn't properly deal with all the input combinations. This is one more case, I don't see why this is any different than say a function that forgot to deal with negative numbers or something like that. |
@ti-s My current plan is this: have |
I have never used C# but one difference could be that in Julia, it is common to type function signatures as loosely as possible and rely on duck typing to catch errors. If that is not the case in C#, it might happen more often in Julia that one gets silently wrong results when passing a Here is an example from base that gives unexpected results with
It would be safer to have comparisons return a This is also different to SQL, which uses 3VL but silently interprets |
Yeah, things can go wrong with this. But I almost feel that in this example The core problem is that the convention in base now is that the lifted version of a function that you get with a
I know, but I don't like that one bit, I think it makes things way too difficult. I also don't see any chance that base will adopt this convention for things like |
I agree that To clarify, I don't propose to copy SQL. I mentioned the difference to SQL as a potential advantage of my proposal. An alternative could be to have comparisons with Not being able to use dotted operators because of the inconsistency with |
From the discussions in JuliaStats/NullableArrays.jl#85, https://github.com/JuliaData/Roadmap.jl/issues/3, and JuliaData/DataFramesMeta.jl#58 it seems that the main open question is the behavior of comparison operators. I understand that there are good reasons for the current behavior of
NAable
s. Unfortunately, it could lead to subtle errors, e.g.:If comparison operators return
NAable{Bool}
instead, and a function likebool{T<:Bool}(x::NAable{T}) = isna(x) ? false : x.value
exists, the above would become:Maybe one can automatically treat
NA
asfalse
in filter-like contexts like Boolean indexing, generators,@where
, ..., so one does not have to wrap such conditions inbool(...)
. But because it is not safe to assume that the author of an arbitrary function usingif ... else .. end
or the ternary operator has anticipated the possibility ofNA
s, an error should be thrown ifNA
occurs in a comparison in a control flow statement. As Stefan Karpinsky pointed out in JuliaStats/NullableArrays.jl#85 (comment), it could still be possible to allow non-NA
NAable{Bool}
s in such situations.The text was updated successfully, but these errors were encountered: