Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save and load unexpectedly modify types #84

Open
BoZenKhaa opened this issue Feb 19, 2021 · 1 comment
Open

save and load unexpectedly modify types #84

BoZenKhaa opened this issue Feb 19, 2021 · 1 comment

Comments

@BoZenKhaa
Copy link

BoZenKhaa commented Feb 19, 2021

I have played with the updated BSON after #29 and I still seem to get unexpected behavior:

  1. Changed type of nested dictionaries on reload
julia> inner_d = Dict(:v=>0)
Dict{Symbol,Int64} with 1 entry:
  :v => 0

julia> outer_d = Dict(:d=>inner_d)
Dict{Symbol,Dict{Symbol,Int64}} with 1 entry:
  :d => Dict(:v=>0)

julia> save("test.bson", outer_d)

julia> load("test.bson")
BSON.BSONDict with 1 entry:
  :d => BSON.BSONDict(:v=>0)

According to README, i would expect both the inner and outer dictionaries to be of the Dict type when loaded.

  1. Lost array type on reload
julia> v = [zeros(1) for i in 1:2]
2-element Array{Array{Float64,1},1}:
 [0.0]
 [0.0]

julia> D = Dict(:d=>v)
Dict{Symbol,Array{Array{Float64,1},1}} with 1 entry:
  :d => [[0.0], [0.0]]

julia> save("test_v.bson", D)

julia> load("test_v.bson")
BSON.BSONDict with 1 entry:
  :d => Any[[0.0], [0.0]]

Here, I would expect the loaded dictionary to be Dict, not BSONDict and the array elements to be of type Array{Float64,1}, not Any.

Quickly looking through the issues, such effects of save and load could imo be the cause of some of the reports (#76, #75).

I think it would be worthwhile to mention this behaviour in the README to save people headaches with unexpected errors.

PS: I was having similar issues even before the merge of #29, the change in #29 at least made these issues much easier to track.

@BoZenKhaa BoZenKhaa changed the title save and load modify saved structures save and load unexpectedly modify types of values Feb 19, 2021
BoZenKhaa added a commit to BoZenKhaa/BSON.jl that referenced this issue Feb 19, 2021
There are ongoing issues with BSON changing types of saved structures JuliaIO#84 that may lead to cryptic error messages. It would be nice to have a warning in the README before this behaviour addressed in some way.
@BoZenKhaa
Copy link
Author

I made a PR to add warning to the README: #85

@BoZenKhaa BoZenKhaa changed the title save and load unexpectedly modify types of values save and load unexpectedly modify types Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant