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

jldsave function API #297

Merged
merged 7 commits into from
Apr 23, 2021
Merged

jldsave function API #297

merged 7 commits into from
Apr 23, 2021

Conversation

JonasIsensee
Copy link
Collaborator

This PR adds a new API function that leverages julia's keyword argument syntax.

julia> using JLD2
[ Info: Precompiling JLD2 [033835bb-8acc-5ee8-8aae-3f567f8a3819]

julia> hello = 1
1

julia> jldsave("test.jld2"; hello, world = 2)

julia> using FileIO

julia> load("test.jld2")
Dict{String, Any} with 2 entries:
  "hello" => 1
  "world" => 2

@codecov
Copy link

codecov bot commented Apr 6, 2021

Codecov Report

Merging #297 (582356e) into master (8cb9a08) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #297      +/-   ##
==========================================
+ Coverage   90.30%   90.32%   +0.02%     
==========================================
  Files          26       26              
  Lines        2641     2647       +6     
==========================================
+ Hits         2385     2391       +6     
  Misses        256      256              
Impacted Files Coverage Δ
src/JLD2.jl 91.86% <ø> (ø)
src/loadsave.jl 95.23% <100.00%> (+0.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8cb9a08...582356e. Read the comment docs.

@lhupe
Copy link
Contributor

lhupe commented Apr 6, 2021

hmm, I like this syntax a lot, but I'm starting to think that it might be more useful to add it to the FileIO API (as an alternative zero-argument method). After all, it does basically the same thing (store key-value pairs in a JLD2 file) and I personally think the current FileIO.save("filename.jld2", "key1", value1, "key2", value2) syntax is a bit weird.

@JonasIsensee JonasIsensee merged commit ee85fa7 into master Apr 23, 2021
@johnnychen94
Copy link
Member

johnnychen94 commented Apr 23, 2021

A compatible workaround to JuliaIO/FileIO.jl#324:

fileio_save(f::File{format"JLD2"}, ::Nothing; kwargs...) = jldsave(FileIO.filename(f); kwargs...)

and use save("test.jld2", nothing; x, y, zebra=z). A little bit weird for nothing though but it works. How do you think of this?

@JonasIsensee
Copy link
Collaborator Author

JonasIsensee commented Apr 24, 2021

A compatible workaround to JuliaIO/FileIO.jl#324:

fileio_save(f::File{format"JLD2"}, ::Nothing; kwargs...) = jldsave(FileIO.filename(f); kwargs...)

and use save("test.jld2", nothing; x, y, zebra=z). A little bit weird for nothing though but it works. How do you think of this?

Thank you for the suggestion but I'm not convinced.
I don't think that is a valid option. I'd rather use a new function name than having to pass an arbitrary nothing just to make dispatch work.

@johnnychen94
Copy link
Member

JuliaIO/FileIO.jl#324 is a breaking change so even if it's approved, it needs time to adopt. Before that actually get supported, save("test.jld2", nothing; x, y, zebra=z) is a forward-compatible workaround.

@JonasIsensee JonasIsensee deleted the jldsave branch May 13, 2021 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants