-
Notifications
You must be signed in to change notification settings - Fork 21
address vcat return inconsistency #187
Changes from 5 commits
1689728
a36f6a4
5d9d982
4aa635c
7d948a0
1b64de2
9cc8381
b8c87b5
bb0b1ee
b8211a9
d28b7b8
6c30d14
2e2b98a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,3 +311,14 @@ function Base.empty!(X::NullableVector) | |
empty!(X.isnull) | ||
return X | ||
end | ||
|
||
notnullarray = Union{filter!(x -> !isa(x, Type{NullableArray}), subtypes(AbstractArray))...} | ||
notnullmatrix = typeintersect(notnullarray, AbstractMatrix) | ||
notnullvector = typeintersect(notnullarray, AbstractVector) | ||
|
||
Base.vcat{T <: notnullarray}(A::T, B::NullableArray) = Base.vcat(NullableArray(A), B) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wasteful since it creates a copy. Maybe we can use this trick to force creating a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, no need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this case of adding an empty NullableArray to the beginning of the |
||
Base.vcat{T <: notnullmatrix}(A::T, B::NullableArray) = Base.vcat(NullableArray(A), B) | ||
Base.vcat{T <: notnullvector}(A::T, B::NullableVector) = Base.vcat(NullableArray(A), B) | ||
|
||
Base.hcat{T <: notnullvector}(A::T, B::NullableArray) = Base.hcat(NullableArray(A), B) | ||
Base.hcat{T <: notnullmatrix}(A::T, B::NullableArray) = Base.hcat(NullableArray(A), B) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
## Lifted operators | ||
|
||
importall Base.Operators | ||
import Base: promote_op, abs, abs2, sqrt, cbrt, scalarmin, scalarmax, isless | ||
import Base: abs, abs2, cbrt, isless, promote_op, scalarmin, scalarmax, sqrt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reverted |
||
using Compat: @compat, @functorize | ||
|
||
if isdefined(Base, :fieldname) && Base.fieldname(Nullable, 1) == :hasvalue # Julia 0.6 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,4 +223,21 @@ module TestNullableVector | |
X = NullableArray(A, M) | ||
empty!(X) | ||
@test isempty(X) | ||
|
||
@test typeof(hcat(NullableArray(1:2), 3:4)) == NullableArrays.NullableArray{Int64,2} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
@test typeof(hcat(1:2, NullableArray(3:4))) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(vcat(NullableArray(1:2), 3:4)) == NullableArrays.NullableArray{Int64,1} | ||
@test typeof(vcat(1:2, NullableArray(3:4))) == NullableArrays.NullableArray{Int64,1} | ||
|
||
@test typeof(vcat(NullableArray([1 2]), [3 4])) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(vcat([1 2], NullableArray([3 4]))) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(hcat(NullableArray(1:2), 3:4, 5:6)) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(hcat(1:2, NullableArray(3:4), 5:6)) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(hcat(1:2, 3:4, NullableArray(5:6))) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(vcat(NullableArray(1:2), 3:4, 5:6)) == NullableArrays.NullableArray{Int64,1} | ||
@test typeof(vcat(1:2, NullableArray(3:4), 5:6)) == NullableArrays.NullableArray{Int64,1} | ||
@test typeof(vcat(1:2, 3:4, NullableArray(5:6))) == NullableArrays.NullableArray{Int64,1} | ||
@test typeof(vcat(NullableArray([1 2]), [3 4], [5 6])) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(vcat([1 2], NullableArray([3 4]), [5 6])) == NullableArrays.NullableArray{Int64,2} | ||
@test typeof(vcat([1 2], [3 4], NullableArray([5 6]))) == NullableArrays.NullableArray{Int64,2} | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't need this. Just
AbstractArray
should be enough, and the most specific method will take precedence.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using
AbstractArray
there's no way to exit thevcat -> vcat
loop and it results in StackOverflow. We either eternally prepend empty NullableArrays (vcat(NullableVector{eltype(A)}(), A, B)
) or eternally try to convert A to aNullableArray
(vcat(NullableArray(A), B)
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now realize that if I call
typed_hcat
,typed_vcat
instead of callinghcat/vcat
I can probably avoid the StackOverflow while using the simplerAbstractArray
as you suggested.