|
268 | 268 | @test Mt == permutedims(m)
|
269 | 269 | # 167
|
270 | 270 | @test !Tables.istable(Matrix{Union{}}(undef, 2, 3))
|
| 271 | + |
| 272 | + # Tables.Columns roundtrip |
| 273 | + X = [1 0 0; 0 1 0; 0 0 1] |
| 274 | + X′ = Tables.matrix(Tables.Columns(Tables.table(X))) |
| 275 | + @test X′ == X |
| 276 | + # test for presence of superfluous wrapping |
| 277 | + @test typeof(X′) == typeof(X) |
271 | 278 | end
|
272 | 279 |
|
273 | 280 | import Base: ==
|
@@ -524,22 +531,22 @@ struct DummyRow <: Tables.AbstractRow end
|
524 | 531 | @test_throws ErrorException("`Tables.columnnames` must be specifically overloaded for DummyRow <: Union{AbstractRow, AbstractColumns}`") Tables.columnnames(r)
|
525 | 532 | end
|
526 | 533 |
|
527 |
| -struct Columns <: Tables.AbstractColumns |
| 534 | +struct TestColumns <: Tables.AbstractColumns |
528 | 535 | a::Vector{Int}
|
529 | 536 | b::Vector{Union{Float64, Missing}}
|
530 | 537 | c::Vector{String}
|
531 | 538 | end
|
532 | 539 |
|
533 |
| -Tables.getcolumn(r::Columns, i::Int) = getfield(r, i) |
534 |
| -Tables.getcolumn(r::Columns, nm::Symbol) = getfield(r, nm) |
535 |
| -Tables.getcolumn(r::Columns, ::Type{T}, i::Int, nm::Symbol) where {T} = getfield(r, i) |
536 |
| -Tables.columnnames(r::Columns) = fieldnames(Columns) |
| 540 | +Tables.getcolumn(r::TestColumns, i::Int) = getfield(r, i) |
| 541 | +Tables.getcolumn(r::TestColumns, nm::Symbol) = getfield(r, nm) |
| 542 | +Tables.getcolumn(r::TestColumns, ::Type{T}, i::Int, nm::Symbol) where {T} = getfield(r, i) |
| 543 | +Tables.columnnames(r::TestColumns) = fieldnames(TestColumns) |
537 | 544 |
|
538 | 545 | struct DummyCols <: Tables.AbstractColumns end
|
539 | 546 |
|
540 | 547 | @testset "AbstractColumns" begin
|
541 | 548 |
|
542 |
| - col = Columns([1, 2], [missing, 3.14], ["hey", "ho"]) |
| 549 | + col = TestColumns([1, 2], [missing, 3.14], ["hey", "ho"]) |
543 | 550 |
|
544 | 551 | @test Base.IteratorSize(typeof(col)) == Base.HasLength()
|
545 | 552 | @test length(col) == 3
|
@@ -572,6 +579,20 @@ struct DummyCols <: Tables.AbstractColumns end
|
572 | 579 | @test_throws ErrorException("`Tables.columnnames` must be specifically overloaded for DummyCols <: Union{AbstractRow, AbstractColumns}`") Tables.columnnames(c)
|
573 | 580 | end
|
574 | 581 |
|
| 582 | +@testset "Tables.Columns" begin |
| 583 | + X = (A=[1,2], B=[im, -im], C=["kirk", "spock"]) |
| 584 | + |
| 585 | + Xc = Tables.Columns(X) |
| 586 | + @test Tables.schema(X) == Tables.schema(Xc) |
| 587 | + for i ∈ 1:3 |
| 588 | + @test Tables.getcolumn(X, i) == Tables.getcolumn(Xc, i) |
| 589 | + end |
| 590 | + for i ∈ (:A, :B, :C) |
| 591 | + @test Tables.getcolumn(X, i) == Tables.getcolumn(Xc, i) |
| 592 | + end |
| 593 | + @test Tables.columnnames(X) == Tables.columnnames(Xc) |
| 594 | +end |
| 595 | + |
575 | 596 | struct IsRowTable
|
576 | 597 | rows::Vector{NamedTuple}
|
577 | 598 | end
|
|
0 commit comments