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

More robust isiterabletable #11

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
6 changes: 5 additions & 1 deletion src/TableTraits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ export supports_get_columns_copy, get_columns_copy
export supports_get_columns_copy_using_missing, get_columns_copy_using_missing
export supports_get_columns_view, get_columns_view

# Taken from Setfield.jl
@generated constructor_of(::Type{T}) where T =
getfield(parentmodule(T), nameof(T))

# Iterable table trait

function isiterabletable(x::T) where {T}
isiterable(x) || return false

if Base.IteratorEltype(x)==Base.HasEltype()
et = Base.eltype(x)
if et <: NamedTuple
if constructor_of(et) === NamedTuple
return true
elseif et===Any
return missing
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ other_array = [1,2,3]
without_eltype = (i for i in table_array)

@test isiterabletable(table_array)
@test isiterabletable((NamedTuple{(:x, :y), T} where T)[(x=1, y=1)])
@test !isiterabletable(other_array)
@test isiterabletable(without_eltype)===missing
@test isiterabletable(any_table_array)===missing
Expand Down