JLD.jl icon indicating copy to clipboard operation
JLD.jl copied to clipboard

Incorporating JLD into package, and using custom types from that package

Open IanButterworth opened this issue 6 years ago • 4 comments

I'd like to use JLD within a package to save custom types from that same package. What's the correct way to do this? Call the package itself from within addrequire() (which causes an error if I do it as below)? Or should the package in addrequire() be a lighter-weight types-only package? Is there a performance hit if it's the former?

i.e. within the package ThisPackage, this errors

jldopen(filepath, "w") do file
        addrequire(file,ThisPackage)
        write(file, "x", x)
    end
ERROR: UndefVarError: module_parent not defined
Stacktrace:
 [1] _istoplevel(::Module) at C:\Users\IanB\.julia\packages\JLD\1BoSz\src\JLD.jl:1253
 [2] addrequire(::JLD.JldFile, ::Module) at C:\Users\IanB\.julia\packages\JLD\1BoSz\src\JLD.jl:1256
...

IanButterworth avatar Feb 26 '19 16:02 IanButterworth

Also, is there any reason to not do this with JLD, over HDF5.jl etc.? I'm using JLD as there were examples, and I couldn't immediately find how to use custom types in HDF5

IanButterworth avatar Feb 26 '19 16:02 IanButterworth

I just realized that the error above is a <1.0 error that's fixed in master. It would be good to push a new release out to catch that @JeffBezanson

IanButterworth avatar Feb 26 '19 23:02 IanButterworth

Hi ! Is there a plan to make a tag a out of the latest master ? Facing the same issue...

virgodi avatar Jun 26 '19 08:06 virgodi

Have the same issue, gives me ERROR: LoadError: UndefVarError: module_parent not defined error. Test code attached.

debugCode.jl:

using JLD
push!(LOAD_PATH, pwd());

import debugTypes: Type1, Type2
import debugTypes

a = Type1(3.14);
b = Type2(100.0);

filepath = "test_data.jld"
jldopen(filepath,"w") do file
    addrequire(file, debugTypes)
    write(file, "a", a, "b", b)
end

debugTypes.jl:

module debugTypes

using Dates
export Type1, Type2

mutable struct Type1
    var1::Float64
end

struct Type2
    var2::Float64
end

end

truedichotomy avatar Nov 14 '19 14:11 truedichotomy