Skip to content

Commit

Permalink
Merge pull request #40 from JuliaEarth/fix
Browse files Browse the repository at this point in the history
Fix the implementation of the AbstractArray interface of CoDaArray
  • Loading branch information
juliohm authored Nov 27, 2023
2 parents 319bc63 + 082d4e9 commit e01b5e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/codaarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ function CoDaArray(table)
CoDaArray{length(PARTS),Tuple(PARTS)}(data)
end

Base.getindex(array::CoDaArray{D,PARTS}, ind) where {D,PARTS} = Composition(PARTS, getfield(array, :data)[:, ind])

Base.size(array::CoDaArray) = (size(getfield(array, :data), 2),)

Base.getindex(array::CoDaArray{D,PARTS}, ind::Int) where {D,PARTS} = Composition(PARTS, getfield(array, :data)[:, ind])

Base.IndexStyle(::Type{<:CoDaArray}) = IndexLinear()

function Base.getproperty(array::CoDaArray{D,PARTS}, part::Symbol) where {D,PARTS}
Expand Down
3 changes: 3 additions & 0 deletions test/codaarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
@test array[1] == Composition(a=1, b=4, c=7)
@test array[2] == Composition(a=2, b=5, c=8)
@test array[3] == Composition(a=3, b=6, c=9)
@test array[[1, 2]] == [Composition(a=1, b=4, c=7), Composition(a=2, b=5, c=8)]
@test array[[1, 3]] == [Composition(a=1, b=4, c=7), Composition(a=3, b=6, c=9)]
@test array[[2, 3]] == [Composition(a=2, b=5, c=8), Composition(a=3, b=6, c=9)]
@test Tables.istable(array)
@test Tables.rowaccess(array) == true
@test Tables.rows(array) == rows
Expand Down

0 comments on commit e01b5e6

Please sign in to comment.