rafaqz / DimensionalData.jl

Named dimensions and indexing for julia arrays and other data
https://rafaqz.github.io/DimensionalData.jl/stable/
MIT License
281 stars 42 forks source link

Implementing the TableTraits interface #390

Closed sethaxen closed 2 years ago

sethaxen commented 2 years ago

Not every package that uses tables uses the Tables interface. Notably, the QueryVerse packages and the Julia VSCode plug-in all use the TableTraits interface instead, so it's useful to implement both.

Here is one way to implement the interface for DimensionalData, modeled after how DataFrames does it.

function IteratorInterfaceExtensions.getiterator(da::AbstractDimArray)
    return Tables.datavaluerows(Tables.columntable(da))
end
IteratorInterfaceExtensions.isiterable(da::AbstractDimArray) = true
TableTraits.isiterabletable(da::AbstractDimArray) = true

function IteratorInterfaceExtensions.getiterator(ds::AbstractDimStack)
    return Tables.datavaluerows(Tables.columntable(ds))
end
IteratorInterfaceExtensions.isiterable(ds::AbstractDimStack) = true
TableTraits.isiterabletable(ds::AbstractDimStack) = true
rafaqz commented 2 years ago

Nice. Guessing these deps have minimal startup time?

If so, a PR adding this would be great.