JuliaIO / JLD2.jl

HDF5-compatible file format in pure Julia
Other
549 stars 85 forks source link

JLD2 saves PyObjects as NULL #411

Closed morripau closed 11 months ago

morripau commented 2 years ago

Here's a simple example. When my_scaler is loaded it's loaded as PyObject NULL.

using JLD2, ScikitLearn
@sk_import preprocessing : StandardScaler

X = zeros(5,2)

for i = 1:5
    for j= 1:2
        X[i, j] = 2*i+j
    end
end

my_scaler = StandardScaler().fit(X)
@save "my_scaler.jld2" my_scaler
@load "my_scaler.jld2" my_scaler

my_scaler
JonasIsensee commented 2 years ago

Hi @morripau ,

on the julia side, a PyObject is really just a pointer. Therefore the default is to just not store anything. (the pointer would be invalid upon loading)

However, it should be possible to implement something like https://github.com/JuliaPy/PyCallJLD.jl for JLD2. Then, one would use pickle to serialize the pyobject and place the bytes into the JLD2 file.