Skip to content

Commit

Permalink
special case of NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Jan 29, 2024
1 parent 6875a81 commit ee6918c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ function _defVar(ds::AbstractDataset,name::SymbolOrString,data,nctype,vardimname
end
end

# make sure a fill value is set
maskingvalue_nan = maskingvalue(ds) isa Number && isnan(maskingvalue(ds))

# make sure a fill value is set if we deduce from the type of data
# that it is needed
if (Tmaskingvalue <: T) && !haskey(attrib,"_FillValue") &&
!haskey(kwargs,:fillvalue)
!haskey(kwargs,:fillvalue) && !maskingvalue_nan
push!(attrib,"_FillValue" => fillvalue(nctype))
end

Expand Down
4 changes: 0 additions & 4 deletions test/memory_dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ function CDM.dim(md::MemoryDataset,name::SymbolOrString)
end

CDM.varnames(ds::MemoryDataset) = collect(keys(ds.variables))

CDM.variable(ds::MemoryDataset,variablename::SymbolOrString) = ds.variables[String(variablename)]


CDM.attribnames(md::Union{MemoryDataset,MemoryVariable}) = keys(md._attrib)
CDM.attrib(md::Union{MemoryDataset,MemoryVariable},name::SymbolOrString) = md._attrib[String(name)]

Expand Down
8 changes: 8 additions & 0 deletions test/test_scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,11 @@ end

@test nonuniontype(Missing,Union{Float64,Missing}) == Float64
@test nonuniontype(Missing,Union{Missing,Float64}) == Float64



fname = tempname()
data = rand(4,5)
ds = TDS(fname,"c", maskingvalue = NaN)
ncv = defVar(ds,"data",data,("lon","lat"))
@test !haskey(ncv.attrib,"_FillValue")

0 comments on commit ee6918c

Please sign in to comment.