Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reinterpret(Union{Missing, T}, ::Vector{Union{Missing, U}}) #31152

Open
cstjean opened this issue Feb 22, 2019 · 1 comment
Open

Allow reinterpret(Union{Missing, T}, ::Vector{Union{Missing, U}}) #31152

cstjean opened this issue Feb 22, 2019 · 1 comment
Labels
missing data Base.missing and related functionality

Comments

@cstjean
Copy link
Contributor

cstjean commented Feb 22, 2019

This works:

julia> v = [1,2,3,4]
4-element Array{Int64,1}:
 1
 2
 3
 4

julia> reinterpret(Some{Int64}, v)
4-element reinterpret(Some{Int64}, ::Array{Int64,1}):
 1
 2
 3
 4

It would be very nice if this could be supported, too:

julia> v2 = [1,2,3,4,missing]
5-element Array{Union{Missing, Int64},1}:
 1       
 2       
 3       
 4       
  missing

julia> reinterpret(Union{Missing, Some{Int64}}, v)
ERROR: ArgumentError: cannot reinterpret `Int64` `Union{Missing, Some{Int64}}`, type `Union{Missing, Some{Int64}}` is not a bits type
Stacktrace:
 [1] (::getfield(Base, Symbol("#throwbits#200")))(::Type{Int64}, ::Type{Union{Missing, Some{Int64}}}, ::Type{Union{Missing, Some{Int64}}}) at ./reinterpretarray.jl:16
 [2] reinterpret(::Type{Union{Missing, Some{Int64}}}, ::Array{Int64,1}) at ./reinterpretarray.jl:33
 [3] top-level scope at none:0

I've explained the use case on discourse. Briefly, when working with Unitful vectors, one often has to take out the units (eg. to make a linear regression), then tack them back on the result. Both operations could conceivably be done allocation-free with reinterpret, but are very slow on vectors that contain missings.

@nalimilan
Copy link
Member

See #26681 about a similar issue with convert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing data Base.missing and related functionality
Projects
None yet
Development

No branches or pull requests

2 participants