Skip to content

Commit 0272d7a

Browse files
authored
Skip over function handles in v7.3 format (#146)
This is similar to #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.
1 parent bcb0604 commit 0272d7a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/MAT_HDF5.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ function m_read(g::HDF5Group)
229229
data = str2eltype_matlab[mattype][]
230230
end
231231
return SparseMatrixCSC(convert(Int, HDF5.a_read(g, sparse_attr_matlab)), length(jc)-1, jc, ir, data)
232+
elseif mattype == "function_handle"
233+
@warn "MATLAB $mattype values are currently not supported"
234+
return missing
232235
else
233236
error("Cannot read from a non-struct group, type was $mattype")
234237
end

test/read.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,16 @@ let objtestfile = "figure.fig"
213213
@test vars["hgS_070000"]["type"] == "figure"
214214
end
215215

216-
# test reading file containing Matlab table and datetime objects
216+
# test reading file containing Matlab function handle, table, and datetime objects
217217
# since we don't support these objects, just make sure that there are no errors
218218
# reading the file and that the variables are there and replaced with `missing`
219+
let objtestfile = "function_handles.mat"
220+
vars = matread(joinpath(dirname(@__FILE__), "v7.3", objtestfile))
221+
@test "sin" in keys(vars)
222+
@test ismissing(vars["sin"])
223+
@test "anonymous" in keys(vars)
224+
@test ismissing(vars["anonymous"])
225+
end
219226
let objtestfile = "struct_table_datetime.mat"
220227
vars = matread(joinpath(dirname(@__FILE__), "v7.3", objtestfile))["s"]
221228
@test "testTable" in keys(vars)

test/v7.3/function_handles.mat

21.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)