Skip to content

Commit

Permalink
Check that fid[name] is a HDF5.Group in h5isvalidcsc
Browse files Browse the repository at this point in the history
  • Loading branch information
severinson committed Jun 24, 2021
1 parent 4d6ce36 commit b2d8a86
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/H5Sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct H5SparseMatrixCSC{Tv, Ti<:Integer} <: SparseArrays.AbstractSparseMatrixCS
function H5SparseMatrixCSC(fid::HDF5.File, name::AbstractString, rows::UnitRange{Int}, cols::UnitRange{Int}) where {Tv,Ti<:Integer}
name in keys(fid) || throw(ArgumentError("$name is not in $fid"))
g = fid[name]
g isa HDF5.Group || throw(ArgumentError("fid[name] is $g, but must be a HDF5.Group"))
"m" in keys(g) || throw(ArgumentError("m is not in $g"))
"n" in keys(g) || throw(ArgumentError("n is not in $g"))
"colptr" in keys(g) || throw(ArgumentError("colptr is not in $g"))
Expand Down Expand Up @@ -305,6 +306,7 @@ Return `true` if `fid[name]` is a valid `H5SparseMatrixCSC` dataset, and `false`
function h5isvalidcsc(fid::HDF5.File, name::AbstractString)
name in keys(fid) || return false
g = fid[name]
g isa HDF5.Group || return false
"m" in keys(g) || return false
"n" in keys(g) || return false
"colptr" in keys(g) || return false
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ using HDF5, SparseArrays
@test H5Sparse.h5isvalidcsc(filename, name)
delete_object(fid[name], "m")
@test !H5Sparse.h5isvalidcsc(fid, name)

fid["foo"] = 10
@test !H5Sparse.h5isvalidcsc(fid, "foo")
end

0 comments on commit b2d8a86

Please sign in to comment.