Skip to content

rconvert only called for reconstructed types in vectors; or, vector of reconstructed types is mistyped #691

@BioTurboNick

Description

@BioTurboNick

There could be a couple ways to look at this issue, depending on what is intended and what the goals should be.

Here, I'm loading two items from a JLD2 file: a DataFrame, and a vector of DataFrames, using the @load x y macro. Both were saved in an earlier version of DataFrames lacking the metadata field.

The first DataFrame loads as a ReconstructedMutable. The vector of DataFrame errors because it is unable to convert the ReconstructedMutable to DataFrame:

MethodError: Cannot `convert` an object of type JLD2.ReconstructedMutable{Symbol("DataFrames.DataFrame"), (:columns, :colindex), Tuple{Any, DataFrames.Index}} to an object of type DataFrames.DataFrame

The function `convert` exists, but no method is defined for this combination of argument types.

rconvert(::Type, ::JLD2.ReconstructedMutable{Symbol("DataFrames.DataFrame"), (:columns, :colindex), Tuple{Any, DataFrames.Index}}) from custom_serialization.jl:11
lconvert(::JLD2.MappedRepr{DataFrames.DataFrame, JLD2.RelOffset}, ::JLD2.JLDFile{JLD2.MmapIO}, ::Ptr{Nothing}, ::JLD2.RelOffset) from writing_datatypes.jl:339
macro expansion from dataio.jl:125
macro expansion from simdloop.jl:77
read_array!(::Vector{DataFrames.DataFrame}, ::JLD2.JLDFile{JLD2.MmapIO}, ::JLD2.MappedRepr{DataFrames.DataFrame, JLD2.RelOffset}) from dataio.jl:122
read_array(::JLD2.JLDFile{JLD2.MmapIO}, ::JLD2.ReadDataspace, ::JLD2.ReadRepresentation, ::JLD2.DataLayout, ::JLD2.Filters.FilterPipeline{Tuple{}}, ::JLD2.RelOffset, ::Vector{JLD2.ReadAttribute}) from datasets.jl:248
read_data(::JLD2.JLDFile{JLD2.MmapIO}, ::JLD2.MappedRepr{Any, JLD2.RelOffset}, ::Tuple{JLD2.ReadDataspace, JLD2.RelOffset, JLD2.DataLayout, JLD2.Filters.FilterPipeline{Tuple{}}}, ::Vector{JLD2.ReadAttribute}) from datasets.jl:136
read_data(::JLD2.JLDFile{JLD2.MmapIO}, ::JLD2.ReadDataspace, ::JLD2.H5Datatype, ::JLD2.DataLayout, ::JLD2.Filters.FilterPipeline{Tuple{}}, ::JLD2.RelOffset, ::Vector{JLD2.ReadAttribute})from datasets.jl:84
load_dataset(::JLD2.JLDFile{JLD2.MmapIO}, ::JLD2.RelOffset) from datasets.jl:48

So one leg of this issue is that perhaps the array should be typed to hold the ReconstructedMutable instead, so that this does not error, and everything loads as reconstructed types.

However, it was actually quite nice that I could just define rconvert and get the vector and its elements to be converted automatically on loading without having to define the old DataFrame struct type and changing the loading code, and I wish I could have the same method be called to convert the DataFrame that isn't in the vector:

JLD2.rconvert(::Type{DataFrame}, x::JLD2.ReconstructedMutable{Symbol("DataFrames.DataFrame"), (:columns, :colindex), Tuple{Any, DataFrames.Index}}) = DataFrame(getfield(x, :fields)...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions