JuliaIO / JLD2.jl

HDF5-compatible file format in pure Julia
Other
553 stars 88 forks source link

change item in existing collection #124

Closed romainvieme closed 1 month ago

romainvieme commented 5 years ago

Hi, I am using JLD2 to save the results of scientific computations and I wonder if there is a way to modify an array inside a JLD file. Here is an example of what I would like to do

using JLD2
myarray= [1 2 3]
@save "testfile.jld2" myarray
jldopen("testfile.jld2", "r+") do myfile
    myfile["myarray"][2]=4
end
jldopen("testfile.jld2", "r") do myfile
    myfile["myarray"]
end

and I would like to get [1 4 3] instead of the current [1 2 3]. I found that it is possible to make the change persist by opening the file with h5open but not with jldopen. Is there a way to make such persistent changes in JLD2 ?

JonasIsensee commented 4 years ago

Currently that is not possible but it would surely be nice to have.

JonasIsensee commented 3 years ago

Out of place modification is possible by deleting a dataset and writing to it again

A list of what is needed for this:

For modifying arrays:

For scalars:

koehlerson commented 3 years ago

@JonasIsensee how would I delete the dataset? I'm trying to do the same right now as the author of the issue

edit: nvm its just the dictionary interface with delete!

JonasIsensee commented 1 month ago

As of version v0.4.53 Dataset objects support getindex and setindex! which should behave as the syntax suggests. This allows updating values of arrays.