Skip to content

Commit

Permalink
Fix collect of ConcatDiskArray (#427)
Browse files Browse the repository at this point in the history
* Fix collect of concat arrays

* Move generator function
  • Loading branch information
danlooo authored Aug 29, 2024
1 parent eb75dfc commit df7dd5d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Cubes/Cubes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function Base.propertynames(a::YAXArray, private::Bool=false)
end
end


Base.Generator(f, A::YAXArray) = Base.Generator(f, parent(A))
Base.ndims(a::YAXArray{<:Any,N}) where {N} = N
Base.eltype(a::YAXArray{T}) where {T} = T
function Base.permutedims(c::YAXArray, p)
Expand Down
4 changes: 2 additions & 2 deletions src/YAXTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Window
end


function PickAxisArray(parent, indmask, perm = nothing)
function PickAxisArray(parent, indmask, perm=nothing)
f = findall(isequal(true), indmask)
f2 = findall(isequal(Colon()), indmask)
f3 = findall(i -> isa(i, Tuple{Int,Int}), indmask)
Expand Down Expand Up @@ -79,4 +79,4 @@ function Base.eltype(p::PickAxisArray{T}) where {T}
end
end
Base.getindex(p::PickAxisArray, i::CartesianIndex) = p[i.I...]
end
end
19 changes: 18 additions & 1 deletion test/Cubes/transformedcubes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,24 @@
@test caxes(newcube) == (X(1.0:4.0), Y([1, 2, 3, 4, 5]), Z(["A", "B", "C"]))
@test ndims(newcube) == 3
@test size(newcube) == (4, 5, 3)
@test newcube[:, :, :] == cat(data..., dims = 3)
@test newcube[:, :, :] == cat(data..., dims=3)
@test getattributes(newcube) == reduce(merge, props)
end
@testset "ConcatDiskArray" begin
using Zarr
lon_range = X(-180:180)
lat_range = Y(-90:90)
data = [exp(cosd(lon)) + 3 * (lat / 90) for lon in lon_range, lat in lat_range]
a = YAXArray((lon_range, lat_range), data)
ds_ram = Dataset(; properties=Dict(), a)
path = tempname()
savedataset(ds_ram; path=path)
ds_disk = open_dataset(path)
a_ram = cat(ds_ram.a[X=1:100], ds_ram.a[X=101:200], dims=:X)
a_disk = cat(ds_disk.a[X=1:100], ds_disk.a[X=101:200], dims=:X)

@test collect(x for x in a_disk) == collect(x for x in a_ram)

rm(path, recursive=true)
end
end

0 comments on commit df7dd5d

Please sign in to comment.