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

Use TableTraits.isiterabletable in rows and columns #89

Merged
merged 1 commit into from
May 4, 2019
Merged
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
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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could further simplify this: TableTraits.isiterabletable(x) will return true if Base.isiterable(T) is true, so we don't need that second test. Also, I think we also want to take this branch if TableTraits.isiterabletable(x)===missing, right? So I think the test should probably read elseif TableTraits.isiterabletable(x) !== false.

But having said this, this PR is clearly fixing a bug already, so thanks for opening it!

Copy link
Member Author

Choose a reason for hiding this comment

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

You're clearly the expert here, so feel free to open a PR to improve this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Will do once I'm done with my current travel stint. @quinnj could you tag a bug fix release that includes this PR soon? Tables v0.2.0 broke the entire file IO story in Queryverse, and this PR fixes that.

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