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

T in Dict{Symbol, T} is not preserved #89

Open
CarloLucibello opened this issue Feb 27, 2021 · 1 comment
Open

T in Dict{Symbol, T} is not preserved #89

CarloLucibello opened this issue Feb 27, 2021 · 1 comment

Comments

@CarloLucibello
Copy link
Collaborator

The value type of Dict with symbols keys is not preserved (it is broadened to Any)

julia> d = Dict(:a=>1, :b=>2)
Dict{Symbol, Int64} with 2 entries:
  :a => 1
  :b => 2

julia> bson("test.bson", d = d)

julia> BSON.load("test.bson")
Dict{Symbol, Any} with 1 entry:
  :d => Dict{Symbol, Any}(:a=>1, :b=>2)
@s-baumann
Copy link

Maybe related to this, I see something similar with dataframes.

using DataFrames, BSON
temp_path = ENV["TEMP"]
aa = DataFrame(Dict(:A => [1,2,3], :B => [:a,:b,:c]))
typeof(aa.B) # Vector{Symbol} (alias for Array{Symbol, 1})

# Now saving it
fpath = joinpath(temp_path, "test.bson")
dic = Dict()
dic[:dframe] = aa
BSON.bson(fpath, dic)

# Now loading it one of the columns has its type changed.
dic2 = BSON.load(fpath)
bb = dic2[:dframe]
typeof(bb.B) # Vector{Any} (alias for Array{Any, 1})

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

2 participants