Skip to content

Commit

Permalink
fix Vector{Any} attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed May 28, 2024
1 parent 354de30 commit f7383a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/netcdf_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ end

function nc_put_att(ncid::Integer,varid::Integer,name::SymbolOrString,data::Vector{Any})
T = promote_type(typeof.(data)...)
nc_put_att(ncid,varid,name,ncType[T],data)
@debug "promoted type for attribute $T"
nc_put_att(ncid,varid,name,ncType[T],T.(data))
end

# convert e.g. ranges to vectors
Expand Down
10 changes: 10 additions & 0 deletions test/test_attrib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ end

rm(filename)


#filename = "/tmp/mytest.nc"

# test untyped attributes
filename = tempname()
vector_attrib = Any[Int32(1),Int32(2)]
ds = NCDataset(filename,"c")
# test deletion of attributes
ds.attrib["vector_attrib"] = vector_attrib
@test ds.attrib["vector_attrib"] == vector_attrib
close(ds)

0 comments on commit f7383a6

Please sign in to comment.