Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TableTraits.jl integration #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
julia 0.7-
Indexing
Indexing
IteratorInterfaceExtensions
TableTraits
TableTraitsUtils
1 change: 1 addition & 0 deletions src/MinimumViableTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import LinearAlgebra: cross, ×
using Unicode
using Indexing
#using DataStreams
import IteratorInterfaceExtensions, TableTraits, TableTraitsUtils

export colnames, columns, accelerators, project, Project, accelerate, rename, Rename

Expand Down
14 changes: 14 additions & 0 deletions src/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ function Table{names}(nt::NamedTuple{names2, <:Tuple{Vararg{AbstractVector}}}, i
end
end

# TableTraits.jl integration
function Table(source)
iit = TableTraits.isiterabletable(source)
if iit===true
cols, names = TableTraitsUtils.create_columns_from_iterabletable(source, na_representation=:datavalue)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment about this: you could also call this with na_representation=:missing, and then any column with missing would be a Vector{Union{T,Missing}}. With the current code version any column with missing you would get as a DataValueVector{T}.

elseif iit===missing
error("Not yet implemented.")
else
error("Argument is not a table.")
end

return Table(NamedTuple{tuple(names...),Tuple{typeof.(cols)...}}(cols))
end

# Helpers to get the data directly from the Table struct
accelerators(::AbstractVector{<:NamedTuple}) = ()
accelerators(t::Table) = Core.getfield(t, :accelerators)
Expand Down