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

Work around undefined values when converting DataArrays? #107

Open
johnmyleswhite opened this issue Jul 26, 2014 · 8 comments
Open

Work around undefined values when converting DataArrays? #107

johnmyleswhite opened this issue Jul 26, 2014 · 8 comments

Comments

@johnmyleswhite
Copy link
Member

Should we make the following snippet work?

julia> using DataArrays

julia> da = data(Array(Any, 8))
8-element DataArray{Any,1}:
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef
 #undef

julia> da[2:8] = [1, 2, 2, 2, 1, 6, 6]
7-element Array{Int64,1}:
 1
 2
 2
 2
 1
 6
 6

julia> convert(DataVector{Int64}, data(da))
ERROR: access to undefined reference
 in copy! at abstractarray.jl:148
 in convert at /Users/johnmyleswhite/.julia/v0.3/DataArrays/src/dataarray.jl:609

Note that this fails even when there are missing values:

julia> da = DataArray(Array(Any, 8), trues(8))
8-element DataArray{Any,1}:
 NA
 NA
 NA
 NA
 NA
 NA
 NA
 NA

julia> da[2:8] = [1, 2, 2, 2, 1, 6, 6]
7-element Array{Int64,1}:
 1
 2
 2
 2
 1
 6
 6

julia> convert(DataVector{Int64}, data(da))
ERROR: access to undefined reference
 in copy! at abstractarray.jl:148
 in convert at /Users/johnmyleswhite/.julia/v0.3/DataArrays/src/dataarray.jl:609

When there are missing values, this seems like a clear bug to me. When there aren't missing values, this might be the right behavior.

@simonster
Copy link
Member

We should definitely be able to convert DataArrays with missing values. If there are actually undefined values, I think it's fine for conversion to fail, since it fails for Arrays as well.

@johnmyleswhite
Copy link
Member Author

Ok. I'll deal with that when updating pull request for conversion functions.

@davidanthoff
Copy link

I just ran into this bug, i.e. I'm trying to convert a DataArray{Any} into a typed DataArray, and that doesn't work if there are NAs in origin data. @johnmyleswhite

@johnmyleswhite
Copy link
Member Author

Not likely to have time to fix up the conversion PR soon, but this specific bug should be easy to fix if somebody has a little time.

@121onto
Copy link

121onto commented Sep 18, 2015

Bump.

@johnmyleswhite
Copy link
Member Author

I doubt I'll work on this since we're going to release a beta of NullableArrays soon and I'll be shifting all of my work over to that package.

@davidagold
Copy link

Speaking of which, I'll go ahead and fix this in NullableArrays right now -- at least for when the values are missing.

@amellnik
Copy link

I think this can be closed -- things like

da = @data([NA, 1.0,2.0])
da2 = convert(DataArrays.DataArray{Int32,1}, da)

work now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants