Skip to content
This repository was archived by the owner on May 5, 2019. It is now read-only.

Remove unused functions and increase test coverage #31

Merged
merged 4 commits into from
May 12, 2017
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
1 change: 0 additions & 1 deletion src/DataTables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export @~,
tail,

# Remove after deprecation period
read_rda,
pool,
pool!

Expand Down
13 changes: 1 addition & 12 deletions src/abstractdatatable/abstractdatatable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -659,17 +659,6 @@ unique!(dt) # modifies dt
"""
(unique, unique!)

function nonuniquekey(dt::AbstractDataTable)
# Here's another (probably a lot faster) way to do `nonunique`
# by grouping on all columns. It will fail if columns cannot be
# made into CategoricalVector's.
gd = groupby(dt, _names(dt))
idx = [1:length(gd.idx)][gd.idx][gd.starts]
res = fill(true, nrow(dt))
res[idx] = false
res
end

# Count the number of missing values in every column of an AbstractDataTable.
function colmissing(dt::AbstractDataTable) # -> Vector{Int}
nrows, ncols = size(dt)
Expand Down Expand Up @@ -701,7 +690,7 @@ without(dt::AbstractDataTable, c::Any) = without(dt, index(dt)[c])

# catch-all to cover cases where indexing returns a DataTable and copy doesn't
Base.hcat(dt::AbstractDataTable, x) = hcat!(dt[:, :], x)
Base.hcat(dt1::AbstractDataTable, dt2::AbstractDataTable) = hcat!(dt[:, :], dt2)
Base.hcat(dt1::AbstractDataTable, dt2::AbstractDataTable) = hcat!(dt1[:, :], dt2)

Base.hcat(dt::AbstractDataTable, x, y...) = hcat!(hcat(dt, x), y...)
Base.hcat(dt1::AbstractDataTable, dt2::AbstractDataTable, dtn::AbstractDataTable...) = hcat!(hcat(dt1, dt2), dtn...)
Expand Down
17 changes: 17 additions & 0 deletions test/cat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ module TestCat

@test isequal(dt2, DataTables.hcat!(dt2))

@testset "hcat ::AbstractDataTable" begin
dt = DataTable(A = repeat('A':'C', inner=4), B = 1:12)
gd = groupby(dt, :A)
answer = DataTable(A = fill('A', 4), B = 1:4, A_1 = 'B', B_1 = 5:8, A_2 = 'C', B_2 = 9:12)
@test hcat(gd...) == answer
answer = answer[1:4]
@test hcat(gd[1], gd[2]) == answer
end

@testset "hcat ::Vectors" begin
dt = DataTable()
DataTables.hcat!(dt, NullableCategoricalVector(1:10))
@test isequal(dt[1], NullableCategoricalVector(1:10))
DataTables.hcat!(dt, NullableArray(1:10))
@test isequal(dt[2], NullableArray(1:10))
end

#
# vcat
#
Expand Down
46 changes: 46 additions & 0 deletions test/datatable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,50 @@ module TestDataTable
b = unstack(dt, :variable, :value)
@test a == b == DataTable(id = Nullable[1, 2], a = [3, Nullable()], b = [Nullable(), 4])
end

@testset "rename" begin
dt = DataTable(A = 1:3, B = 'A':'C')
@test names(rename(dt, :A, :A_1)) == [:A_1, :B]
@test names(dt) == [:A, :B]
@test names(rename!(dt, :A, :A_1)) == [:A_1, :B]
@test names(dt) == [:A_1, :B]
end

@testset "size" begin
dt = DataTable(A = 1:3, B = 'A':'C')
@test_throws ArgumentError size(dt, 3)
@test length(dt) == 2
@test ndims(dt) == 2
end

@testset "description" begin
dt = DataTable(A = 1:10)
@test head(dt) == DataTable(A = 1:6)
@test head(dt, 1) == DataTable(A = 1)
@test tail(dt) == DataTable(A = 5:10)
@test tail(dt, 1) == DataTable(A = 10)
end

@testset "misc" begin
dt = DataTable(Any[collect('A':'C')])
@test sprint(dump, dt) == """
DataTables.DataTable 3 observations of 1 variables
x1: Array{Char}((3,))
1: Char A
2: Char B
3: Char C
"""
dt = DataTable(A = 1:12, B = repeat('A':'C', inner=4))
@test DataTables.without(dt, 1) == DataTable(B = repeat('A':'C', inner=4))
end

@testset "column conversions" begin
dt = DataTable(Any[collect(1:10), collect(1:10)])
@test !isa(dt[1], NullableArray)
nullable!(dt, 1)
@test isa(dt[1], NullableArray)
@test !isa(dt[2], NullableArray)
nullable!(dt, [1,2])
@test isa(dt[1], NullableArray) && isa(dt[2], NullableArray)
end
end
5 changes: 5 additions & 0 deletions test/duplicates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ module TestDuplicates
@test isequal(updt, unique(pdt))
unique!(pdt)
@test isequal(pdt, updt)

@testset "missing" begin
dt = DataTable(A = 1:12, B = repeat('A':'C', inner=4))
@test DataTables.colmissing(dt) == [0, 0]
end
end