Skip to content

Commit

Permalink
improved behavior of Tables.Columns (#226)
Browse files Browse the repository at this point in the history
* improved behavior of Tables.Columns

* bumped version

* increased version number

* removed check that Tables.Column is being passed a table

* fixed small issues caused by last commit
  • Loading branch information
ExpandingMan authored Jan 22, 2021
1 parent 36be703 commit cfc4984
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tables"
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
authors = ["quinnj <[email protected]>"]
version = "1.2.2"
version = "1.3.0"

[deps]
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Expand Down
3 changes: 3 additions & 0 deletions src/Tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ end

Columns(x::AbstractColumns) = x

# Columns can only wrap something that is a table, so we pass the schema through
schema(x::Columns) = schema(getx(x))

const RorC2 = Union{Row, Columns}

getx(x::RorC2) = getfield(x, :x)
Expand Down
33 changes: 27 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ end
@test Mt == permutedims(m)
# 167
@test !Tables.istable(Matrix{Union{}}(undef, 2, 3))

# Tables.Columns roundtrip
X = [1 0 0; 0 1 0; 0 0 1]
X′ = Tables.matrix(Tables.Columns(Tables.table(X)))
@test X′ == X
# test for presence of superfluous wrapping
@test typeof(X′) == typeof(X)
end

import Base: ==
Expand Down Expand Up @@ -524,22 +531,22 @@ struct DummyRow <: Tables.AbstractRow end
@test_throws ErrorException("`Tables.columnnames` must be specifically overloaded for DummyRow <: Union{AbstractRow, AbstractColumns}`") Tables.columnnames(r)
end

struct Columns <: Tables.AbstractColumns
struct TestColumns <: Tables.AbstractColumns
a::Vector{Int}
b::Vector{Union{Float64, Missing}}
c::Vector{String}
end

Tables.getcolumn(r::Columns, i::Int) = getfield(r, i)
Tables.getcolumn(r::Columns, nm::Symbol) = getfield(r, nm)
Tables.getcolumn(r::Columns, ::Type{T}, i::Int, nm::Symbol) where {T} = getfield(r, i)
Tables.columnnames(r::Columns) = fieldnames(Columns)
Tables.getcolumn(r::TestColumns, i::Int) = getfield(r, i)
Tables.getcolumn(r::TestColumns, nm::Symbol) = getfield(r, nm)
Tables.getcolumn(r::TestColumns, ::Type{T}, i::Int, nm::Symbol) where {T} = getfield(r, i)
Tables.columnnames(r::TestColumns) = fieldnames(TestColumns)

struct DummyCols <: Tables.AbstractColumns end

@testset "AbstractColumns" begin

col = Columns([1, 2], [missing, 3.14], ["hey", "ho"])
col = TestColumns([1, 2], [missing, 3.14], ["hey", "ho"])

@test Base.IteratorSize(typeof(col)) == Base.HasLength()
@test length(col) == 3
Expand Down Expand Up @@ -572,6 +579,20 @@ struct DummyCols <: Tables.AbstractColumns end
@test_throws ErrorException("`Tables.columnnames` must be specifically overloaded for DummyCols <: Union{AbstractRow, AbstractColumns}`") Tables.columnnames(c)
end

@testset "Tables.Columns" begin
X = (A=[1,2], B=[im, -im], C=["kirk", "spock"])

Xc = Tables.Columns(X)
@test Tables.schema(X) == Tables.schema(Xc)
for i 1:3
@test Tables.getcolumn(X, i) == Tables.getcolumn(Xc, i)
end
for i (:A, :B, :C)
@test Tables.getcolumn(X, i) == Tables.getcolumn(Xc, i)
end
@test Tables.columnnames(X) == Tables.columnnames(Xc)
end

struct IsRowTable
rows::Vector{NamedTuple}
end
Expand Down

2 comments on commit cfc4984

@quinnj
Copy link
Member

@quinnj quinnj commented on cfc4984 Jan 22, 2021

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/28453

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.0 -m "<description of version>" cfc4984bef1e416e58863adbef9f4da9392d3ffd
git push origin v1.3.0

Please sign in to comment.