queryverse / queryverse/DataValues.jl
Should comparison operators return Bool values?
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 14
- Forks
- 6
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 2
Description
From the discussions in https://github.com/JuliaStats/NullableArrays.jl/pull/85, https://github.com/JuliaData/Roadmap.jl/issues/3, and https://github.com/JuliaStats/DataFramesMeta.jl/issues/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 NAables. Unfortunately, it could lead to subtle errors, e.g.:
julia> include("NAable.jl"); using .NAables
julia> a = [NAable(1), NAable(-1), NAable{Int}()]
3-element Array{NAables.NAable{Int64},1}:
1
-1
#NA
julia> positive = broadcast(>=, a, 0)
3-element Array{Bool,1}:
true
false
false
julia> b = Any[NA, NA, NA]; b[positive] = "+"; b[~positive] = "-"; b
3-element Array{Any,1}:
"+"
"-"
"-"
julia> getsign(x) = x < 0 ? "-" : "+"
getsign (generic function with 1 method)
julia> getsign.(a)
3-element Array{String,1}:
"+"
"-"
"+"
If comparison operators return NAable{Bool} instead, and a function like
bool{T<:Bool}(x::NAable{T}) = isna(x) ? false : x.value exists, the above would become:
julia> include("NAable3VL.jl"); using .NAables
julia> a = [NAable(1), NAable(-1), NAable{Int}()]
3-element Array{NAables.NAable{Int64},1}:
1
-1
#NA
julia> positive = broadcast(>=, a, 0)
3-element Array{NAables.NAable{Bool},1}:
true
false
#NA
julia> b = Any[NA, NA, NA]; b[bool.(positive)] = "+"; b[bool.(~positive)] = "-"; b
3-element Array{Any,1}:
"+"
"-"
NA
julia> getsign(x) = x < 0 ? "-" : "+"
getsign (generic function with 1 method)
julia> getsign.(a)
ERROR: TypeError: non-boolean (NAables.NAable{Bool}) used in boolean context
Maybe one can automatically treat NA as false in filter-like contexts like Boolean indexing, generators, @where, ..., so one does not have to wrap such conditions in bool(...). But because it is not safe to assume that the author of an arbitrary function using if ... else .. end or the ternary operator has anticipated the possibility of NAs, an error should be thrown if NA occurs in a comparison in a control flow statement. As Stefan Karpinsky pointed out in https://github.com/JuliaStats/NullableArrays.jl/pull/85#issuecomment-240859040, it could still be possible to allow non-NA NAable{Bool}s in such situations.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read the current behavior illustrated through NAable.jl and the proposed behavior in NAable3VL.jl, then review the linked NullableArrays.jl, Roadmap.jl, and DataFramesMeta.jl discussions. The issue needs a settled decision on comparison results and their behavior in indexing and control flow before implementation can be considered done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100