Skip to content

Commit

Permalink
Skip over function handles in v7.3 format
Browse files Browse the repository at this point in the history
This is similar to JuliaIO#129 which returns `missing` for unhandled data
types in HDF5 Datasets; function handles are stored as HDF5 groups, so
a different explicit check is required to skip over them.
  • Loading branch information
jmert committed Nov 1, 2020
1 parent 57b8483 commit 3ffa265
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/MAT_HDF5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ function m_read(g::HDF5Group)
data = str2eltype_matlab[mattype][]
end
return SparseMatrixCSC(convert(Int, HDF5.a_read(g, sparse_attr_matlab)), length(jc)-1, jc, ir, data)
elseif mattype == "function_handle"
@warn "MATLAB $mattype values are currently not supported"
return missing
else
error("Cannot read from a non-struct group, type was $mattype")
end
Expand Down
9 changes: 8 additions & 1 deletion test/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,16 @@ let objtestfile = "figure.fig"
@test vars["hgS_070000"]["type"] == "figure"
end

# test reading file containing Matlab table and datetime objects
# test reading file containing Matlab function handle, table, and datetime objects
# since we don't support these objects, just make sure that there are no errors
# reading the file and that the variables are there and replaced with `missing`
let objtestfile = "function_handles.mat"
vars = matread(joinpath(dirname(@__FILE__), "v7.3", objtestfile))
@test "sin" in keys(vars)
@test ismissing(vars["sin"])
@test "anonymous" in keys(vars)
@test ismissing(vars["anonymous"])
end
let objtestfile = "struct_table_datetime.mat"
vars = matread(joinpath(dirname(@__FILE__), "v7.3", objtestfile))["s"]
@test "testTable" in keys(vars)
Expand Down
Binary file added test/v7.3/function_handles.mat
Binary file not shown.

0 comments on commit 3ffa265

Please sign in to comment.