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

[Feautre] Explicitly remap types #191

Closed
BioTurboNick opened this issue May 8, 2020 · 3 comments
Closed

[Feautre] Explicitly remap types #191

BioTurboNick opened this issue May 8, 2020 · 3 comments

Comments

@BioTurboNick
Copy link

I have an issue where I'd like to change a type in my package but have JLD2 files with data saved.

I'd like to easily load this data and then map it to the new type.

The solution that comes to mind is that I can preserve the old type as something like:

struct MyType
    i::Int
    j::Int
end

struct OldMyType
    i::Int
end

data = load("mydata.jl", "MyType" => :OldMyType)

# work to convert from old type to the new type

Maybe there's a way to make this work (it is looking to use convert which seems tantilizing as a way to plug in the correct function) but I seem to not be implementing it right. If this is possible, it could be added to the documentation.

@JonasIsensee
Copy link
Collaborator

This would indeed be nice.
A workaround might be to introduce an intermediate step.

in one julia session you define

struct MyType
    i::Int
end
struct MyNewType
    i::Int
    j::Int
end
data = load("mydata.jld2")
#convert types
save("intermediate.jld2", data)

and in the next julia session you define

struct MyType
    i::Int
    j::Int
end
struct MyNewType
    i::Int
    j::Int
end
data = load("mydata.jld2")
#trivial conversion from MyNewType to MyType
save("updated.jld2", data)

@JonasIsensee
Copy link
Collaborator

Hi @BioTurboNick ,

#316 now implements this in principle. There is no real API yet, but it should at least work.

@JonasIsensee
Copy link
Collaborator

#316 wasn't merged but #376 with just this feature just landed in v0.4.21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants