Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Wrong return type for .== #142

Closed
Tracked by #148
nalimilan opened this issue Aug 28, 2016 · 5 comments
Closed
Tracked by #148

Wrong return type for .== #142

nalimilan opened this issue Aug 28, 2016 · 5 comments

Comments

@nalimilan
Copy link
Member

I see this on both 0.4 and 0.5:

julia> x = NullableArray(1:3)
x3-element NullableArrays.NullableArray{Int64,1} :
== 1
 2
 3

julia> x == x
ERROR: TypeError: non-boolean (Nullable{Bool}) used in boolean context
 in ==(::NullableArrays.NullableArray{Int64,1}, ::NullableArrays.NullableArray{Int64,1}) at ./abstractarray.jl:1405

julia> x .== x
3-element NullableArrays.NullableArray{Int64,1}:
 1
 1
 1

Looks like a problem with broadcast:

julia> broadcast(==, x, x)
3-element NullableArrays.NullableArray{Int64,1}:
 1
 1
 1
@davidagold
Copy link
Contributor

Is this perhaps related to JuliaLang/julia#17172 ? I haven't yet incorporated that fix into the NullableArray broadcast implementation.

@nalimilan
Copy link
Member Author

Not sure, but certainly worth a try.

@joshbode
Copy link

joshbode commented Dec 7, 2016

For non-numeric types this causes a MethodError:

julia> x = NullableVector{String}(["a", "b", "c", "d"]); x[4] = Nullable();
julia> x .== x
ERROR: MethodError: Cannot `convert` an object of type Bool to an object of type String
This may have arisen from a call to the constructor String(...),
since type constructors fall back to convert methods.
 in setindex! at /Users/josh/.julia/v0.5/NullableArrays/src/indexing.jl:60 [inlined]
 in _setindex! at ./multidimensional.jl:441 [inlined]
 in setindex! at ./abstractarray.jl:832 [inlined]
 in macro expansion at /Users/josh/.julia/v0.5/NullableArrays/src/broadcast.jl:128 [inlined]
 in macro expansion at ./simdloop.jl:73 [inlined]
 in macro expansion at /Users/josh/.julia/v0.5/NullableArrays/src/broadcast.jl:122 [inlined]
 in #_broadcast!#20(::Bool, ::Base.Broadcast.#_broadcast!, ::Base.#==, ::NullableArrays.NullableArray{String,1}, ::Tuple{Tuple{Bool},Tuple{Bool}}, ::Tuple{Tuple{Int64},Tuple{Int64}}, ::Tuple{NullableArrays.NullableArray{String,1},NullableArrays.NullableArray{String,1}}, ::Type{Val{2}}) at /Users/josh/.julia/v0.5/NullableArrays/src/broadcast.jl:112
 in (::Base.Broadcast.#kw##_broadcast!)(::Array{Any,1}, ::Base.Broadcast.#_broadcast!, ::Function, ::NullableArrays.NullableArray{String,1}, ::Tuple{Tuple{Bool},Tuple{Bool}}, ::Tuple{Tuple{Int64},Tuple{Int64}}, ::Tuple{NullableArrays.NullableArray{String,1},NullableArrays.NullableArray{String,1}}, ::Type{Val{2}}) at ./<missing>:0
 in #broadcast!#22(::Bool, ::Function, ::Function, ::NullableArrays.NullableArray{String,1}, ::NullableArrays.NullableArray{String,1}, ::Vararg{NullableArrays.NullableArray{String,1},N}) at /Users/josh/.julia/v0.5/NullableArrays/src/broadcast.jl:176
 in (::Base.Broadcast.#kw##broadcast!)(::Array{Any,1}, ::Base.Broadcast.#broadcast!, ::Function, ::NullableArrays.NullableArray{String,1}, ::NullableArrays.NullableArray{String,1}, ::Vararg{NullableArrays.NullableArray{String,1},N}) at ./<missing>:0
 in broadcast(::Function, ::NullableArrays.NullableArray{String,1}, ::NullableArrays.NullableArray{String,1}) at ./<missing>:0
 in .==(::NullableArrays.NullableArray{String,1}, ::NullableArrays.NullableArray{String,1}) at /Users/josh/.julia/v0.5/NullableArrays/src/broadcast.jl:209

@cjprybol
Copy link
Contributor

this works now

julia> using NullableArrays

julia> x = NullableArray(1:3)
3-element NullableArrays.NullableArray{Int64,1}:
 1
 2
 3

julia> x .== x
3-element NullableArrays.NullableArray{Bool,1}:
 true
 true
 true

julia> x = NullableArray(["a", "b", "c", Nullable()])
4-element NullableArrays.NullableArray{String,1}:
 "a"
 "b"
 "c"
 #NULL

julia> x .== x
4-element NullableArrays.NullableArray{Bool,1}:
 true
 true
 true
 #NULL

@nalimilan
Copy link
Member Author

Indeed. Likely fixed by #166.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants