Skip to content

Commit

Permalink
Fixes create_dataset for compound types. Closes JuliaIO#1068
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasgal committed May 16, 2023
1 parent 5d82668 commit b1a5f73
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/typeconversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ end

# These will use finalizers. Close them eagerly to avoid issues.
datatype(::T) where {T} = Datatype(hdf5_type_id(T), true)
datatype(::Type{T}) where T = Datatype(hdf5_type_id(T), isstructtype(T))
datatype(x::AbstractArray{T}) where {T} = Datatype(hdf5_type_id(T), true)

hdf5_type_id(::Type{T}) where {T} = hdf5_type_id(T, Val(isstructtype(T)))
Expand Down
24 changes: 24 additions & 0 deletions test/compound.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ mutable struct MutableBar
x::Int64
end

@testset "create_dataset (compound)" begin
bars = [Bar(1, 2, true), Bar(3, 4, false), Bar(5, 6, true), Bar(7, 8, false)]
fn = tempname()
h5open(fn, "w") do h5f
d = create_dataset(h5f, "the/bars", Bar, ((2,), (-1,)); chunk=(100,))
d[1:2] = bars[1:2]
end

h5open(fn, "cw") do h5f
d = h5f["the/bars"]
HDF5.set_extent_dims(d, (4,))
d[3:4] = bars[3:4]
end

thebars = h5open(fn, "r") do h5f
read(h5f, "the/bars")
end

@test 4 == length(thebars)
@test 1 == thebars[1].a
@test true == thebars[3].c
@test 8 == thebars[4].b
end

@testset "write_compound" begin
bars = [
[Bar(1, 1.1, true) Bar(2, 2.1, false) Bar(3, 3.1, true)]
Expand Down

0 comments on commit b1a5f73

Please sign in to comment.