Skip to content

Commit

Permalink
Use TableTraits.isiterabletable in rows and columns (#89)
Browse files Browse the repository at this point in the history
Otherwise we misdetect some table types which do not define `Base.iterable`,
like `ExcelFile`.
Add a new test for this pattern.
  • Loading branch information
nalimilan authored and quinnj committed May 4, 2019
1 parent 12b34fb commit 5a8e971
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/fallbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function rows(x::T) where {T}
if columnaccess(T)
cols = columns(x)
return RowIterator(cols, rowcount(cols))
elseif Base.isiterable(T)
elseif TableTraits.isiterabletable(x) === true || Base.isiterable(T)
return IteratorWrapper(IteratorInterfaceExtensions.getiterator(x))
end
throw(ArgumentError("no default `Tables.rows` implementation for type: $T"))
Expand Down Expand Up @@ -149,7 +149,7 @@ end
return buildcolumns(schema(r), r)
elseif TableTraits.supports_get_columns_copy_using_missing(x)
return TableTraits.get_columns_copy_using_missing(x)
elseif Base.isiterable(T)
elseif TableTraits.isiterabletable(x) === true || Base.isiterable(T)
iw = IteratorWrapper(IteratorInterfaceExtensions.getiterator(x))
return buildcolumns(schema(iw), iw)
end
Expand Down
15 changes: 14 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, Tables, TableTraits, DataValues, QueryOperators
using Test, Tables, TableTraits, DataValues, QueryOperators, IteratorInterfaceExtensions

@testset "utils.jl" begin

Expand Down Expand Up @@ -261,6 +261,19 @@ let x=ColumnSource()
@test Tables.columns(x) == TableTraits.get_columns_copy_using_missing(x)
end

struct ColumnSource2
end

IteratorInterfaceExtensions.isiterable(x::ColumnSource2) = true
TableTraits.isiterabletable(::ColumnSource2) = true

IteratorInterfaceExtensions.getiterator(::ColumnSource2) =
Tables.rows((a=[1,2,3], b=[4.,5.,6.], c=["A", "B", "C"]))

let x=ColumnSource2()
@test Tables.columns(x) == (a=[1,2,3], b=[4.,5.,6.], c=["A", "B", "C"])
end

@testset "operations.jl" begin
ctable = (A=[1, missing, 3], B=[1.0, 2.0, 3.0], C=["hey", "there", "sailor"])

Expand Down

0 comments on commit 5a8e971

Please sign in to comment.