Skip to content

Commit

Permalink
fix parent of DimTable for DimStack (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz authored Sep 26, 2023
1 parent 36a2fcb commit c2d24ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Tables.schema(s::AbstractDimStack) = Tables.schema(DimTable(s))
Tables.getcolumn(t, dimnum(t, dim))

function _colnames(s::AbstractDimStack)
dimkeys = map(dim2key, (dims(s)))
dimkeys = map(dim2key, dims(s))
# The data is always the last column/s
(dimkeys..., keys(s)...)
end
Expand Down Expand Up @@ -165,7 +165,7 @@ DimTable with 1024 rows, 4 columns, and schema:
```
"""
struct DimTable <: AbstractDimTable
parent::AbstractDimArray
parent::Union{AbstractDimArray,AbstractDimStack}
colnames::Vector{Symbol}
dimcolumns::Vector{DimColumn}
dimarraycolumns::Vector{DimArrayColumn}
Expand All @@ -177,7 +177,7 @@ function DimTable(s::AbstractDimStack; mergedims=nothing)
dimcolumns = map(d -> DimColumn(d, dims_), dims_)
dimarraycolumns = map(A -> DimArrayColumn(A, dims_), s)
keys = _colnames(s)
return DimTable(first(s), collect(keys), collect(dimcolumns), collect(dimarraycolumns))
return DimTable(s, collect(keys), collect(dimcolumns), collect(dimarraycolumns))
end

function DimTable(xs::Vararg{AbstractDimArray}; layernames=nothing, mergedims=nothing)
Expand Down Expand Up @@ -277,4 +277,4 @@ function IteratorInterfaceExtensions.getiterator(t::DimTable)
return Tables.datavaluerows(Tables.dictcolumntable(t))
end
IteratorInterfaceExtensions.isiterable(::DimTable) = true
TableTraits.isiterabletable(::DimTable) = true
TableTraits.isiterabletable(::DimTable) = true
5 changes: 3 additions & 2 deletions test/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ da2 = DimArray(fill(2, (3, 2, 3)), dimz; name=:data2)
ds = DimStack(da)
t = Tables.columns(ds)
@test t isa DimTable
@test dims(t) == dims(da)
@test dims(t) === dims(da)
@test parent(t) === ds

@test Tables.columns(t) === t
@test t[:X] isa DimColumn
Expand Down Expand Up @@ -164,4 +165,4 @@ end
@test Tables.columnnames(t2) == (:Ti, :geometry, :layer1, :layer2, :layer3)
@test Tables.columnnames(t3) == (:dimensions, :layer1, :layer2, :layer3)
@test Tables.columnnames(t4) == (:band, :geometry, :value)
end
end

0 comments on commit c2d24ea

Please sign in to comment.