JuliaIO / HDF5.jl

Save and load data in the HDF5 file format from Julia
https://juliaio.github.io/HDF5.jl
MIT License
387 stars 140 forks source link

Saving Array of Arrays #282

Open cedeerwe opened 8 years ago

cedeerwe commented 8 years ago

I am having trouble with saving an array of arrays, a simple code:

b = [[i] for i=1:5]
h5open("foo.h5", "w") do file
  write(file, "b", b)
end 

does not work due to the error:

LoadError: MethodError: `write` has no method matching write(::HDF5.HDF5File, ::ASCIIString, ::Array{Union{Array{Float64,1},Tuple{Array{Float64,1},Array{Float64,1}}},1})
Closest candidates are:
  write(::Union{HDF5.HDF5File,HDF5.HDF5Group}, ::Union{ASCIIString,UTF8String}, ::Any, !Matched::Union{ASCIIString,UTF8String}, !Matched::Any, !Matched::Any...)
  write{T<:Base.AbstractPipe}(!Matched::T<:Base.AbstractPipe, ::Any...)
  write{T<:Base.DevNullStream}(!Matched::T<:Base.DevNullStream, ::Any...)
  ...
while loading In[36], in expression starting on line 1

 in getindex at /home/cedeerwe/.julia/v0.4/PyCall/src/PyCall.jl:280
 in pysequence_query at /home/cedeerwe/.julia/v0.4/PyCall/src/conversions.jl:736
 [inlined code] from /home/cedeerwe/.julia/v0.4/PyCall/src/conversions.jl:752
 in pytype_query at /home/cedeerwe/.julia/v0.4/PyCall/src/conversions.jl:774
 in convert at /home/cedeerwe/.julia/v0.4/PyCall/src/conversions.jl:801
 in pycall at /home/cedeerwe/.julia/v0.4/PyCall/src/PyCall.jl:421
 in call at /home/cedeerwe/.julia/v0.4/PyCall/src/PyCall.jl:429
 in close_queued_figs at /home/cedeerwe/.julia/v0.4/PyPlot/src/PyPlot.jl:401

The first two arguments match the required types and the third one should be of type ::Any, which is also correct. I have no idea what the issue might be.

timholy commented 8 years ago

Do you need to use plain HDF5, or can you use JLD? It's been ages since I've read the libhdf5 docs, but my vague memory suggests that libhdf5 might offer more than one way to write such an array in libhdf5. We may have decided that in ambiguous cases, a low-level package like HDF5 shouldn't be in the business of making that choice for the user. But it's been quite a while since I thought about this.

JLD makes those choices for you, and might be easier to use.

--Tim

On Wednesday, January 20, 2016 08:09:32 AM cedeerwe wrote:

I am having trouble with saving an array of arrays, a simple code:

b = [[i] for i=1:5]
h5open("fooh5", "w") do file
  write(file, "b", b)
end

does not work due to the error:

LoadError: MethodError: `write` has no method matching write(::HDF5HDF5File,
::ASCIIString,
::Array{Union{Array{Float64,1},Tuple{Array{Float64,1},Array{Float64,1}}},1}
) Closest candidates are:
  write(::Union{HDF5HDF5File,HDF5HDF5Group},
::Union{ASCIIString,UTF8String}, ::Any,
!Matched::Union{ASCIIString,UTF8String}, !Matched::Any, !Matched::Any)
write{T<:BaseAbstractPipe}(!Matched::T<:BaseAbstractPipe, ::Any)
write{T<:BaseDevNullStream}(!Matched::T<:BaseDevNullStream, ::Any)

while loading In[36], in expression starting on line 1

 in getindex at /home/cedeerwe/julia/v04/PyCall/src/PyCalljl:280
 in pysequence_query at
/home/cedeerwe/julia/v04/PyCall/src/conversionsjl:736 [inlined code] from
/home/cedeerwe/julia/v04/PyCall/src/conversionsjl:752 in pytype_query at
/home/cedeerwe/julia/v04/PyCall/src/conversionsjl:774 in convert at
/home/cedeerwe/julia/v04/PyCall/src/conversionsjl:801 in pycall at
/home/cedeerwe/julia/v04/PyCall/src/PyCalljl:421
 in call at /home/cedeerwe/julia/v04/PyCall/src/PyCalljl:429
 in close_queued_figs at /home/cedeerwe/julia/v04/PyPlot/src/PyPlotjl:401

The first two arguments match the required types and the third one should be of type ::Any, which is also correct I have no idea what the issue might be


Reply to this email directly or view it on GitHub: https://github.com/JuliaLang/HDF5.jl/issues/282