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

Saving a JLSO file that is already constructed seems weird #24

Open
oxinabox opened this issue Oct 4, 2019 · 1 comment
Open

Saving a JLSO file that is already constructed seems weird #24

oxinabox opened this issue Oct 4, 2019 · 1 comment
Milestone

Comments

@oxinabox
Copy link
Member

oxinabox commented Oct 4, 2019

I suspect this is because one is suppose to use write not save if it is already constructed?
We should have some docs that clarify

  • save/load
  • write/read
  • setindex/getindex

Demo of it ibeing weird:

julia> breakfast_jlso = JLSOFile("food"=>"☕️🥓🍳", "cost"=>11.95, "time"=>Time(9,0))
JLSOFile([cost, time, food]; version=v"2.0.0", julia=v"1.2.1-pre.0", format=:julia_serialize, compression=:gzip, image="")

julia> JLSO.save("breakfast.jlso", breakfast_jlso)

julia> JLSO.load("breakfast.jlso", "cost")
[warn | JLSO]: KeyError: key "cost" not found
ERROR: KeyError: key "cost" not found
Stacktrace:
 [1] getindex at ./dict.jl:477 [inlined]
 [2] getindex(::JLSOFile, ::String) at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/serialization.jl:57
 [3] load(::IOStream, ::String) at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/file_io.jl:78
 [4] #9 at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/file_io.jl:70 [inlined]
 [5] #open#312(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(open), ::getfield(JLSO, Symbol("##9#10")){Tuple{String}}, ::String) at ./iostream.jl:375
 [6] open at ./iostream.jl:373 [inlined]
 [7] load(::String, ::String) at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/file_io.jl:70
 [8] top-level scope at REPL[23]:1
caused by [exception 1]
KeyError: key "cost" not found
Stacktrace:
 [1] getindex at ./dict.jl:477 [inlined]
 [2] getindex(::JLSOFile, ::String) at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/serialization.jl:52
 [3] load(::IOStream, ::String) at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/file_io.jl:78
 [4] #9 at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/file_io.jl:70 [inlined]
 [5] #open#312(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(open), ::getfield(JLSO, Symbol("##9#10")){Tuple{String}}, ::String) at ./iostream.jl:375
 [6] open at ./iostream.jl:373 [inlined]
 [7] load(::String, ::String) at /Users/oxinabox/.julia/packages/JLSO/1C0be/src/file_io.jl:70
 [8] top-level scope at REPL[23]:1

julia> JLSO.load("breakfast.jlso", "data")
Dict{String,Any} with 1 entry:
  "data" => JLSOFile([cost, time, food]; version=v"2.0.0", julia=v"1.2.1-pre.0", format=:julia_serialize, compression=:gzip, ima…
@rofinn
Copy link
Member

rofinn commented Oct 7, 2019

Yeah, I think read and write were supported first. save and load were added later to align with the FileIO ecosystem, but we should probably restrict that to something like

JLSO.save("breakfast.jlso", name1 => obj1, name2 => obj2, ...)

Seems like that would also fit the proposed load API better.

@nickrobinson251 nickrobinson251 added this to the 1.0 milestone Oct 17, 2019
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

3 participants