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
19 changes: 19 additions & 0 deletions src/nullablevector.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Base: vcat, hcat, typed_vcat, typed_hcat, promote_eltype

"""
push!{T, V}(X::NullableVector{T}, v::V)

Expand Down Expand Up @@ -311,3 +313,20 @@ function Base.empty!(X::NullableVector)
empty!(X.isnull)
return X
end

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::NullableMatrix)
typed_vcat(promote_eltype(A, B), NullableArray(A), B)
end

function vcat(A::AbstractArray, B::NullableArray)
typed_vcat(promote_eltype(A, B), NullableArray(A), B)
end

NullableVecOrMat = Union{NullableVector, NullableMatrix}
function hcat(A::AbstractVecOrMat, B::NullableVecOrMat)
typed_hcat(promote_eltype(A, B), NullableArray(A), B)
end
26 changes: 26 additions & 0 deletions test/nullablevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,30 @@ module TestNullableVector
X = NullableArray(A, M)
empty!(X)
@test isempty(X)

@test typeof(vcat(NullableArray(1:2), 3:4)) == NullableArray{Int,1}
@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(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}

# 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