JuliaIO / BSON.jl

Other
157 stars 39 forks source link

BSON doesn't seem to work with Pluto.jl and DataFrames.jl #93

Open BoZenKhaa opened 3 years ago

BoZenKhaa commented 3 years ago

The following code

begin
    using BSON
    using DataFrames
    using DrWatson

    b = DataFrame(v = [1,2],l = ["a", "b"])
    DrWatson.save("./test.bson", Dict(:b=>b))

    BSON.load("./test.bson")
end

fails in Pluto notebook with

UndefVarError: DataFrames not defined

    (::BSON.var"#29#30")(::Module, ::String)@extensions.jl:20
    BottomRF@reduce.jl:81[inlined]
    _foldl_impl(::Base.BottomRF{BSON.var"#29#30"}, ::Module, ::Vector{Any})@reduce.jl:58
    foldl_impl@reduce.jl:48[inlined]
    mapfoldl_impl@reduce.jl:44[inlined]
    _mapreduce_dim@reducedim.jl:315[inlined]
    #mapreduce#672@reducedim.jl:310[inlined]
    #reduce#674@reducedim.jl:359[inlined]
    resolve(::Vector{Any})@extensions.jl:20
    (::BSON.var"#33#34")(::BSON.BSONDict)@extensions.jl:53
    _raise_recursive(::BSON.BSONDict, ::IdDict{Any, Any})@read.jl:79
    raise_recursive(::BSON.BSONDict, ::IdDict{Any, Any})@read.jl:89
    (::BSON.var"#43#44")(::BSON.BSONDict, ::IdDict{Any, Any})@extensions.jl:138
    raise_recursive(::BSON.BSONDict, ::IdDict{Any, Any})@read.jl:88
    (::BSON.var"#18#20"{IdDict{Any, Any}})(::BSON.BSONDict)@read.jl:82
    applychildren!(::BSON.var"#18#20"{IdDict{Any, Any}}, ::BSON.BSONDict)@BSON.jl:34
    _raise_recursive(::BSON.BSONDict, ::IdDict{Any, Any})@read.jl:82
    raise_recursive(::BSON.BSONDict, ::IdDict{Any, Any})@read.jl:89
    raise_recursive@read.jl:99[inlined]
    load(::String)@read.jl:104
    top-level scope@Local: 9

This code runs fine in REPL. When using JLD2, there is no problem in loading saved files, which makes me think this may be a BSON issue and not Pluto or DataFrames issue.

haozhangphd commented 3 years ago

This seems to be a duplicate of https://github.com/JuliaIO/BSON.jl/issues/25. Please use BSON.load("./test.bson", @__MODULE__)

BoZenKhaa commented 3 years ago

Thanks a lot for the tip! However, #25 seems to be closed?

haozhangphd commented 3 years ago

Yes it is closed by #91, but the default value of load(x, init=Main) can still cause confusions...

BoZenKhaa commented 3 years ago

Ok, thank you for clarification. I think it could be worthwhile to keep this issue open since the error message seems very cryptic, at least to me. Or should I close this?