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

Override vcat() and (maybe) promote_rule() #167

Open
nalimilan opened this issue Nov 16, 2016 · 1 comment
Open

Override vcat() and (maybe) promote_rule() #167

nalimilan opened this issue Nov 16, 2016 · 1 comment

Comments

@nalimilan
Copy link
Member

We need to override vcat to fix this inconsistency:

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

julia> vcat(1:2, NullableArray(1:2))
4-element Array{Nullable{Int64},1}:
 1
 2
 1
 2

The first case is OK, the second one isn't.

By the way, it could make sense to override promote_rule too, since ideally vcat would use it. Cf. JuliaData/CategoricalArrays.jl#42.

@cjprybol
Copy link
Contributor

issue is with typed_vcat in Base always using the first vcat element to call similar.

julia> similar(full(NullableArray(1:2)), Nullable{Int64}, 4)
4-element NullableArrays.NullableArray{Int64,1}:
 #NULL
 #NULL
 #NULL
 #NULL

julia> similar(full(1:2), Nullable{Int64}, 4)
4-element Array{Nullable{Int64},1}:
 4626872848
 4626872880
 4626872880
 4639814992

See typed_vcat function defintions for AbstractVector & AbstractMatrix. We can fix it by asking typed_vcat to check if any vcat inputs are NullableArrays and, if so, call similar with that input instead of the first.

# fixed
julia> vcat(1:2, NullableArray(1:2))
4-element NullableArrays.NullableArray{Int64,1}:
 1
 2
 1
 2

We need the same change for hcat

# this is wrong
julia> hcat(1:2, NullableArray(1:2))
2×2 Array{Nullable{Int64},2}:
 1  1
 2  2

julia> hcat(NullableArray(1:2), 1:2)
2×2 NullableArrays.NullableArray{Int64,2}:
 1  1
 2  2

And this promote_rule seems wrong? Is promote_rule supposed to be reciprocal?

julia> promote_rule(Nullable{Int64}, Int64)
Nullable{Int64}

julia> promote_rule(Int64, Nullable{Int64})
Union{}

I'll open a pull request with these changes

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

2 participants