Julia - 创建 DataFrame 时出现“UndefRefError: access to undefined reference”

Hen*_*ade 5 dataframe julia

我正在尝试创建一个具有 1 行 10 列的空 DataFrame。在 Julia 0.5 中,我曾经这样做:df = DataFrame(Any,1,10)

当我尝试在 Julia 1.1.1 中执行此操作时,我收到此警告

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

和错误:

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
Run Code Online (Sandbox Code Playgroud)

所以我试过了,df = DataFrame(Matrix{Any}(undef,1,10)) 但我仍然收到UndefRefError: access to undefined reference错误。

那么这样做的正确方法是什么?

Bog*_*ski 2

有趣的。这似乎是 Base 中的一个错误。我会在那里调查。暂时你可以这样做:

DataFrame([Vector{Any}(undef, 1) for i in 1:10])
Run Code Online (Sandbox Code Playgroud)

或者

DataFrame([Any for i in 1:10], Symbol.(["x$i" for i in 1:10]), 1)
Run Code Online (Sandbox Code Playgroud)

或者

DataFrame(Matrix{Any}(missing,1,10))
Run Code Online (Sandbox Code Playgroud)

我将修复弃用警告。