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

Cannot use NullableArray in a data frame #933

Closed
nalimilan opened this issue Mar 26, 2016 · 2 comments
Closed

Cannot use NullableArray in a data frame #933

nalimilan opened this issue Mar 26, 2016 · 2 comments

Comments

@nalimilan
Copy link
Member

I see this with latest master of DataFrames and NullableArrays:

julia> DataFrame(y=NullableArray([1,2]))
ERROR: MethodError: `upgrade_vector` has no method matching upgrade_vector(::NullableArrays.NullableArray{Int64,1})
 in setindex! at /home/milan/.julia/DataFrames/src/dataframe/dataframe.jl:368
 in DataFrame at /home/milan/.julia/DataFrames/src/dataframe/dataframe.jl:104

I suspect I'm missing something, since people seem to be doing this all the time (e.g. JuliaData/DataFramesMeta.jl#42).

@amellnik
Copy link
Contributor

amellnik commented Jul 4, 2016

To anyone else who sees a similar error and ends up here: DataFrames with NullableArray columns need to be constructed all at once, and can't currently have additional columns added. This means that while you can do things like:

DataFrame(Any[NullableArray([1,2])], Symbol[:y])

to construct a DataFrame, you can't subsequently add more columns with something like

df[:col] = NullableArray([1,2])
LoadError: MethodError: `upgrade_vector` has no method matching upgrade_vector(::NullableArrays.NullableArray{Int64,1})
while loading In[9], in expression starting on line 2

 in setindex! at C:\Users\amellnik\.julia\v0.4\DataFrames\src\dataframe\dataframe.jl:368

If you have a DataFrame with NullableArrays for columns and you need to add columns or otherwise convert it to a vanilla DataFrame (with DataArray columns) you can use something like

function NullableDFtoDF!(ndf)
    for c in names(ndf)
        ndf[c] = DataArray(ndf[c].values, ndf[c].isnull)
    end
end

function DFtoNullableDF(df)
    DataFrame(Any[NullableArray(df[c].data,
        Array{Bool}(df[c].na)) for c in names(df)], names(df))
end

@nalimilan
Copy link
Member Author

See #1008.

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

No branches or pull requests

2 participants