Skip to content

Commit 4c28335

Browse files
authored
Set defaultfillval for Real types to typemax (#50)
This was needed for saving rational data to zarr
1 parent af20791 commit 4c28335

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/YAXArrayBase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include("axisarrays/namedtuple.jl")
88

99
defaultfillval(T::Type{<:AbstractFloat}) = convert(T,1e32)
1010
defaultfillval(::Type{Float16}) = Float16(3.2e4)
11-
defaultfillval(T::Type{<:Integer}) = typemax(T)
11+
defaultfillval(T::Type{<:Real}) = typemax(T)
1212
defaultfillval(T::Type{<:AbstractString}) = ""
1313

1414
function __init__()

test/datasets.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,19 @@ function test_write(T)
9999
add_var(ds, 0.5:1:9.5, "lon", ("lon",), Dict("units"=>"degrees_east"))
100100
add_var(ds, 20:-1.0:1, "lat", ("lat",), Dict("units"=>"degrees_north"))
101101
v = add_var(ds, Float32, "tas", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius"))
102-
102+
w = add_var(ds, Rational{Int}, "tas2", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius"))
103103
v[:,:] = collect(reshape(1:200, 10, 20))
104-
105-
@test sort(get_varnames(ds)) == ["lat","lon","tas"]
104+
w[:,:] = collect(reshape(1:200, 10, 20)) .// 2
105+
@test sort(get_varnames(ds)) == ["lat","lon","tas", "tas2"]
106106
@test get_var_dims(ds, "tas") == ["lon", "lat"]
107107
@test get_var_dims(ds, "lon") == ["lon"]
108108
@test get_var_attrs(ds,"tas")["units"] == "Celsius"
109109
h = get_var_handle(ds, "lon")
110110
@test h[:] == 0.5:1:9.5
111111
v = get_var_handle(ds, "tas")
112112
@test v[1:2,1:2] == [1 11; 2 12]
113+
w = get_var_handle(ds, "tas2")
114+
@test w[1:2,1:2] == [1 11; 2 12] .// 2
113115
end
114116

115117
@testset "Writing NetCDF" begin

0 commit comments

Comments
 (0)