Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia - "UndefRefError: access to undefined reference" when creating DataFrame

I'm trying to create an empty DataFrame with 1 row and 10 columns. In Julia 0.5 I used to do: df = DataFrame(Any,1,10)

When I try to do that in Julia 1.1.1 I get this warning

Warning: 'DataFrame(t::Type, nrows::Integer, 
ncols::Integer)' is deprecated, use 
'DataFrame(Matrix{t}(undef, nrows, ncols))' 
instead.

and the error:

ERROR: LoadError: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex at ./array.jl:730 [inlined]
 [2] macro expansion at ./multidimensional.jl:671 [inlined]
 [3] macro expansion at ./cartesian.jl:64 [inlined]
 [4] macro expansion at ./multidimensional.jl:666 [inlined]
 [5] _unsafe_getindex! at ./multidimensional.jl:662 [inlined]
 [6] _unsafe_getindex(::IndexLinear, ::Array{Any,2}, ::Base.Slice{Base.OneTo{Int64}}, ::Int64) at ./multidimensional.jl:656
 [7] getindex at ./multidimensional.jl:642 [inlined]
 [8] #DataFrame#101(::Bool, ::Type, ::Array{Any,2}, ::Array{Symbol,1}) at /home/cambier/julia-1.1.1/Packages/packages/DataFrames/                        CZrca/src/dataframe/dataframe.jl:206
 [9] Type at /home/cambier/julia-1.1.1/Packages/packages/DataFrames/CZrca/src/dataframe/dataframe.jl:206 [inlined] (repeats 2 tim                        es)
 [10] DataFrame(::Type, ::Int64, ::Int64) at ./deprecated.jl:57

So I tried df = DataFrame(Matrix{Any}(undef,1,10)) but I still get the UndefRefError: access to undefined reference error.

So what's the right way to do that?

like image 653
Henrique Andrade Avatar asked Oct 27 '22 12:10

Henrique Andrade


1 Answers

Interesting. It seems to be a bug in Base. I will investigate it there. For the time being you can do:

DataFrame([Vector{Any}(undef, 1) for i in 1:10])

or

DataFrame([Any for i in 1:10], Symbol.(["x$i" for i in 1:10]), 1)

or

DataFrame(Matrix{Any}(missing,1,10))

I will fix the deprecation warning.

like image 170
Bogumił Kamiński Avatar answered Nov 15 '22 06:11

Bogumił Kamiński