From 346d20879716a5d02895158616d768adbc9eca6a Mon Sep 17 00:00:00 2001 From: rafaqz Date: Tue, 13 Aug 2024 22:30:48 +0200 Subject: [PATCH] add DiskArrays forwarding to Variable --- src/messages.jl | 7 +++---- src/variables.jl | 2 +- test/dataset.jl | 11 +++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/messages.jl b/src/messages.jl index 36abb44..088a297 100644 --- a/src/messages.jl +++ b/src/messages.jl @@ -259,7 +259,7 @@ mind["name"] """ function MessageIndex(message::GRIB.Message; index_keys = ALL_KEYS) values = read_message.(Ref(message), index_keys) - headers = Dict(k => v for (k,v) in zip(index_keys, values)) + headers = Dict{String,Any}(k => v for (k, v) in zip(index_keys, values)) offset = Int(message["offset"]) length = message["totalLength"] @@ -280,12 +280,11 @@ function filter_messages(mindexs::Vector{<:MessageIndex}, k::AbstractString, v) end -function filter_messages(mindexs::Vector{<:MessageIndex}; query...) - ms = deepcopy(mindexs) +function filter_messages(ms::Vector{<:MessageIndex}; query...) for (k, v) in query ms = filter_messages(ms, string(k), v) end - ms + return ms end function filter_offsets(mindexs::Vector{<:MessageIndex}, key, val) diff --git a/src/variables.jl b/src/variables.jl index 758da62..64e8336 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -107,7 +107,7 @@ Base.parent(var::Variable) = var.values Base.size(var::Variable) = _size_dims(var.dims) Base.getindex(var::Variable, I...) = getindex(parent(var), I...) -DA.eachchunk(A::Variable) = DA.eachchunks(parent(A)) +DA.eachchunk(A::Variable) = DA.eachchunk(parent(A)) DA.haschunks(A::Variable) = DA.haschunks(parent(A)) DA.readblock!(A::Variable, aout, i::AbstractUnitRange...) = DA.readblock!(parent(A), aout, i...) diff --git a/test/dataset.jl b/test/dataset.jl index 03b5498..7d57a26 100644 --- a/test/dataset.jl +++ b/test/dataset.jl @@ -1,5 +1,6 @@ using GRIBDatasets using Dates +using DiskArrays using Test using GRIBDatasets: getone using GRIBDatasets: Variable @@ -30,6 +31,16 @@ using GRIBDatasets: CDM @test CDM.name(ds[:t]) == CDM.name(ds["t"]) end + @testset "DiskArrays on Variable" begin + var = ds[:z].var + size(var) + @test DiskArrays.eachchunk(var) == DiskArrays.eachchunk(parent(var)) + @test DiskArrays.haschunks(var) == DiskArrays.haschunks(parent(var)) + block = zeros(10, 10, 1, 1, 1) + DiskArrays.readblock!(var, block, 1:10, 1:10, 1:1, 1:1, 1:1) + @test all(block .== var[1:10, 1:10, 1, 1, 1]) + end + @testset "dataset indexing" begin vars = keys(ds) @test vars[1] == "lon"