Skip to content

Commit

Permalink
Merge pull request #41 from JuliaData/jq/promote
Browse files Browse the repository at this point in the history
Fix #23 by defining a few more helper promote_rule definitions
  • Loading branch information
quinnj authored Oct 4, 2017
2 parents 3d11e09 + 14e9325 commit b0a5c55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Nulls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ nulls(::Type{T}, dims...) where {T >: Null} = fill!(Array{T}(dims), null)
nulls(::Type{T}, dims...) where {T} = fill!(Array{Union{T, Null}}(dims), null)

Base.promote_rule(::Type{T}, ::Type{Null}) where {T} = Union{T, Null}
Base.promote_rule(::Type{T}, ::Type{Union{S,Null}}) where {T,S} = Union{promote_type(T, S), Null}
Base.promote_rule(::Type{T}, ::Type{Any}) where {T} = Any
Base.promote_rule(::Type{Any}, ::Type{Null}) = Any
Base.promote_rule(::Type{Null}, ::Type{Any}) = Any
Base.promote_rule(::Type{Null}, ::Type{Null}) = Null
Base.convert(::Type{Union{T, Null}}, x) where {T} = convert(T, x)

# Comparison operators
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ using Base.Test, Nulls

@testset "Nulls" begin

# test promote rules
@test promote_type(Null, Null) == Null
@test promote_type(Null, Int) == Union{Null, Int}
@test promote_type(Int, Null) == Union{Null, Int}
@test promote_type(Int, Any) == Any
@test promote_type(Any, Any) == Any
@test promote_type(Null, Any) == Any
@test promote_type(Any, Null) == Any
@test promote_type(Union{Int, Null}, Null) == Union{Int, Null}
@test promote_type(Null, Union{Int, Null}) == Union{Int, Null}
@test promote_type(Union{Int, Null}, Int) == Union{Int, Null}
@test promote_type(Int, Union{Int, Null}) == Union{Int, Null}
@test promote_type(Any, Union{Int, Null}) == Any
@test promote_type(Union{Int, Null}, Union{Int, Null}) == Union{Int, Null}
@test promote_type(Union{Float64, Null}, Union{String, Null}) == Any
@test promote_type(Union{Float64, Null}, Union{Int, Null}) == Union{Float64, Null}
@test promote_type(Union{Void, Null, Int}, Float64) == Any

bit_operators = [&, |, ]

arithmetic_operators = [+, -, *, /, ^, Base.div, Base.mod, Base.fld, Base.rem]
Expand Down

0 comments on commit b0a5c55

Please sign in to comment.