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

address vcat return inconsistency #187

Closed
wants to merge 13 commits into from
25 changes: 9 additions & 16 deletions src/nullablevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,26 +314,19 @@ function Base.empty!(X::NullableVector)
return X
end

function vcat(A::AbstractVector, B::AbstractVector...)
any(b -> isa(b, NullableArray), B) ?
typed_vcat(promote_eltype(A, B...), NullableArray(A), B...) :
typed_vcat(promote_eltype(A, B...), A, B...)
function vcat(A::AbstractVector, B::NullableVector)
typed_vcat(promote_eltype(A, B), NullableArray(A), B)
Copy link
Member

Choose a reason for hiding this comment

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

Please reduce the number of spaces used for indentation here by 50%

end

function vcat(A::AbstractMatrix, B::AbstractMatrix...)
any(b -> isa(b, NullableArray), B) ?
typed_vcat(promote_eltype(A, B...), NullableArray(A), B...) :
typed_vcat(promote_eltype(A, B...), A, B...)
function vcat(A::AbstractMatrix, B::NullableMatrix)
typed_vcat(promote_eltype(A, B), NullableArray(A), B)
end

function vcat(A::AbstractArray, B::AbstractArray...)
any(b -> isa(b, NullableArray), B) ?
typed_vcat(promote_eltype(A, B...), NullableArray(A), B...) :
typed_vcat(promote_eltype(A, B...), A, B...)
function vcat(A::AbstractArray, B::NullableArray)
typed_vcat(promote_eltype(A, B), NullableArray(A), B)
end

function hcat(A::AbstractVecOrMat, B::AbstractVecOrMat...)
any(b -> isa(b, NullableArray), B) ?
typed_hcat(promote_eltype(A, B...), NullableArray(A), B...) :
typed_hcat(promote_eltype(A, B...), A, B...)
NullableVecOrMat = Union{NullableVector, NullableMatrix}
function hcat(A::AbstractVecOrMat, B::NullableVecOrMat)
typed_hcat(promote_eltype(A, B), NullableArray(A), B)
end
28 changes: 16 additions & 12 deletions test/nullablevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,25 @@ module TestNullableVector
@test typeof(vcat(1:2, NullableArray(3:4))) == NullableArray{Int,1}
@test typeof(vcat(NullableArray([1 2]), [3 4])) == NullableArray{Int,2}
@test typeof(vcat([1 2], NullableArray([3 4]))) == NullableArray{Int,2}
@test typeof(vcat(NullableArray(1:2), 3:4, 5:6)) == NullableArray{Int,1}
@test typeof(vcat(1:2, NullableArray(3:4), 5:6)) == NullableArray{Int,1}
@test typeof(vcat(1:2, 3:4, NullableArray(5:6))) == NullableArray{Int,1}
@test typeof(vcat(NullableArray([1 2]), [3 4], [5 6])) == NullableArray{Int,2}
@test typeof(vcat([1 2], NullableArray([3 4]), [5 6])) == NullableArray{Int,2}
@test typeof(vcat([1 2], [3 4], NullableArray([5 6]))) == NullableArray{Int,2}

@test typeof(hcat(NullableArray(1:2), 3:4)) == NullableArray{Int,2}
@test typeof(hcat(1:2, NullableArray(3:4))) == NullableArray{Int,2}
@test typeof(hcat(NullableArray([1 2]), [3 4])) == NullableArray{Int,2}
@test typeof(hcat([1 2], NullableArray([3 4]))) == NullableArray{Int,2}
@test typeof(hcat(NullableArray(1:2), 3:4, 5:6)) == NullableArray{Int,2}
@test typeof(hcat(1:2, NullableArray(3:4), 5:6)) == NullableArray{Int,2}
@test typeof(hcat(1:2, 3:4, NullableArray(5:6))) == NullableArray{Int,2}
@test typeof(hcat(NullableArray([1 2]), [3 4], [5 6])) == NullableArray{Int,2}
@test typeof(hcat([1 2], NullableArray([3 4]), [5 6])) == NullableArray{Int,2}
@test typeof(hcat([1 2], [3 4], NullableArray([5 6]))) == NullableArray{Int,2}

# add these back if we can find a general solution to propogating array type
# see https://github.com/JuliaLang/julia/issues/2326
# @test typeof(vcat(NullableArray(1:2), 3:4, 5:6)) == NullableArray{Int,1}
# @test typeof(vcat(1:2, NullableArray(3:4), 5:6)) == NullableArray{Int,1}
# @test typeof(vcat(1:2, 3:4, NullableArray(5:6))) == NullableArray{Int,1}
# @test typeof(vcat(NullableArray([1 2]), [3 4], [5 6])) == NullableArray{Int,2}
# @test typeof(vcat([1 2], NullableArray([3 4]), [5 6])) == NullableArray{Int,2}
# @test typeof(vcat([1 2], [3 4], NullableArray([5 6]))) == NullableArray{Int,2}

# @test typeof(hcat(NullableArray(1:2), 3:4, 5:6)) == NullableArray{Int,2}
# @test typeof(hcat(1:2, NullableArray(3:4), 5:6)) == NullableArray{Int,2}
# @test typeof(hcat(1:2, 3:4, NullableArray(5:6))) == NullableArray{Int,2}
# @test typeof(hcat(NullableArray([1 2]), [3 4], [5 6])) == NullableArray{Int,2}
# @test typeof(hcat([1 2], NullableArray([3 4]), [5 6])) == NullableArray{Int,2}
# @test typeof(hcat([1 2], [3 4], NullableArray([5 6]))) == NullableArray{Int,2}
end