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

Division DataArray{Int} / Int results in Array{Any} #295

Open
anriseth opened this issue Jan 5, 2018 · 2 comments
Open

Division DataArray{Int} / Int results in Array{Any} #295

anriseth opened this issue Jan 5, 2018 · 2 comments

Comments

@anriseth
Copy link

anriseth commented Jan 5, 2018

I have come over a problem that depends on whether DataFrames decides that my column is of type Array{Union{Int64, Missings.Missing},1} or DataArrays.DataArray{Int64,1}. Dividing such arrays by an Int results in different element types in the resulting array. I can fix this by doing element-wise division, however, it seems to be unexpected behaviour to me?

In the below, y/minimum(y) results in an array with Anys, instead of Float64s as I expected.

julia> x
2-element Array{Union{Int64, Missings.Missing},1}:
 51
 41
julia> y
2-element DataArrays.DataArray{Int64,1}:
 51
 41
julia> x/minimum(x), y/minimum(y)
([1.2439, 1.0], Any[1.2439, 1.0])

julia> x./minimum(x), y./minimum(y)
([1.2439, 1.0], Union{Float64, Missings.Missing}[1.2439, 1.0])
@nalimilan
Copy link
Member

nalimilan commented Jan 5, 2018

I can't reproduce here on git master and Julia 0.6.2:

julia> y=DataArray([1])
1-element DataArrays.DataArray{Int64,1}:
 1

julia> y/minimum(y)
1-element DataArrays.DataArray{Any,1}:
 1.0

julia> y./minimum(y)
1-element DataArrays.DataArray{Float64,1}:
 1.0

What versions are you using?

EDIT: Silly me, that's the same problem, I just read incorrectly.

@nalimilan
Copy link
Member

That's due to Base.promote_op(/, eltype(y), eltype(y)) returning Any. Looks like we should call Missings.T before calling promote_op, and do Union{T, Missing} again on the result.

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