Skip to content

Commit

Permalink
Re-enable tests of LaTeXStrings and minor code layout fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored Oct 3, 2018
1 parent e015b05 commit a0d44f6
Showing 1 changed file with 47 additions and 35 deletions.
82 changes: 47 additions & 35 deletions test/io.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
module TestIO
using Test, DataFrames, CategoricalArrays, Dates
# commented out for 1.0 release because LaTeXStrings can't load; re-enable once it has updated for 1.0
# using LaTeXStrings
using LaTeXStrings

# # Test LaTeX export
# @testset "LaTeX export" begin
# df = DataFrame(A = 1:4,
# B = ["\$10.0", "M&F", "A~B", "\\alpha"],
# C = [L"\alpha", L"\beta", L"\gamma", L"\sum_{i=1}^n \delta_i"],
# D = [1.0, 2.0, missing, 3.0],
# E = CategoricalArray(["a", missing, "c", "d"]),
# F = Vector{String}(undef, 4)
# )
# str = """
# \\begin{tabular}{r|cccccc}
# \t& A & B & C & D & E & F\\\\
# \t\\hline
# \t1 & 1 & \\\$10.0 & \$\\alpha\$ & 1.0 & a & \\#undef \\\\
# \t2 & 2 & M\\&F & \$\\beta\$ & 2.0 & & \\#undef \\\\
# \t3 & 3 & A\\textasciitilde{}B & \$\\gamma\$ & & c & \\#undef \\\\
# \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & \$\\sum_{i=1}^n \\delta_i\$ & 3.0 & d & \\#undef \\\\
# \\end{tabular}
# """
# @test repr(MIME("text/latex"), df) == str
# end
# Test LaTeX export
@testset "LaTeX export" begin
df = DataFrame(A = 1:4,
B = ["\$10.0", "M&F", "A~B", "\\alpha"],
C = [L"\alpha", L"\beta", L"\gamma", L"\sum_{i=1}^n \delta_i"],
D = [1.0, 2.0, missing, 3.0],
E = CategoricalArray(["a", missing, "c", "d"]),
F = Vector{String}(undef, 4)
)
str = """
\\begin{tabular}{r|cccccc}
\t& A & B & C & D & E & F\\\\
\t\\hline
\t1 & 1 & \\\$10.0 & \$\\alpha\$ & 1.0 & a & \\#undef \\\\
\t2 & 2 & M\\&F & \$\\beta\$ & 2.0 & & \\#undef \\\\
\t3 & 3 & A\\textasciitilde{}B & \$\\gamma\$ & & c & \\#undef \\\\
\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & \$\\sum_{i=1}^n \\delta_i\$ & 3.0 & d & \\#undef \\\\
\\end{tabular}
"""
@test repr(MIME("text/latex"), df) == str
end

#Test HTML output for IJulia and similar
@testset "HTML output" begin
Expand Down Expand Up @@ -86,31 +85,44 @@ module TestIO
lastname = String["Chavez", "Burke", "Richards", "Long", "Rose"],
salary = Union{Float64, Missing}[missing, 46134.1, 45046.2, 30555.6, 88894.1],
rate = Float64[39.44, 33.8, 15.64, 17.67, 34.6],
hired = Union{Date, Missing}[Date("2011-07-07"), Date("2016-02-19"), missing, Date("2002-01-05"), Date("2008-05-15")],
fired = DateTime[DateTime("2016-04-07T14:07:00"), DateTime("2015-03-19T15:01:00"), DateTime("2006-11-18T05:07:00"), DateTime("2002-07-18T06:24:00"), DateTime("2007-09-29T12:09:00")],
hired = Union{Date, Missing}[Date("2011-07-07"), Date("2016-02-19"), missing,
Date("2002-01-05"), Date("2008-05-15")],
fired = DateTime[DateTime("2016-04-07T14:07:00"), DateTime("2015-03-19T15:01:00"),
DateTime("2006-11-18T05:07:00"), DateTime("2002-07-18T06:24:00"),
DateTime("2007-09-29T12:09:00")],
reserved = missings(5)
)
sink = DataStreams.Data.close!(DataStreams.Data.stream!(I, deepcopy(I)))
sch = DataStreams.Data.schema(sink)
@test size(sch) == (5, 8)
@test DataStreams.Data.header(sch) == ["id","firstname","lastname","salary","rate","hired","fired","reserved"]
@test DataStreams.Data.types(sch) == (Int64, Union{String, Missing}, String, Union{Float64, Missing}, Float64, Union{Date, Missing}, DateTime, Missing)
@test sink[:id] == [1,2,3,4,5]
@test DataStreams.Data.header(sch) == ["id", "firstname", "lastname", "salary",
"rate", "hired", "fired", "reserved"]
@test DataStreams.Data.types(sch) == (Int64, Union{String, Missing}, String,
Union{Float64, Missing}, Float64,
Union{Date, Missing}, DateTime, Missing)
@test sink[:id] == [1:5;]

transforms = Dict(1=>x->x+1)
sink = DataStreams.Data.close!(DataStreams.Data.stream!(I, deepcopy(I); append=true, transforms=transforms))
sink = DataStreams.Data.close!(DataStreams.Data.stream!(I, deepcopy(I);
append=true, transforms=transforms))
sch = DataStreams.Data.schema(sink)
@test size(sch) == (10, 8)
@test DataStreams.Data.header(sch) == ["id","firstname","lastname","salary","rate","hired","fired","reserved"]
@test DataStreams.Data.types(sch) == (Int64, Union{String, Missing}, String, Union{Float64, Missing}, Float64, Union{Date, Missing}, DateTime, Missing)
@test sink[:id] == [1,2,3,4,5,2,3,4,5,6]
@test DataStreams.Data.header(sch) == ["id", "firstname", "lastname", "salary",
"rate", "hired", "fired", "reserved"]
@test DataStreams.Data.types(sch) == (Int64, Union{String, Missing}, String,
Union{Float64, Missing}, Float64,
Union{Date, Missing}, DateTime, Missing)
@test sink[:id] == [1:5; 2:6]

sink = DataStreams.Data.close!(Data.stream!(I, DataFrame, deepcopy(I)))
sch = DataStreams.Data.schema(sink)
@test size(sch) == (5, 8)
@test DataStreams.Data.header(sch) == ["id","firstname","lastname","salary","rate","hired","fired","reserved"]
@test DataStreams.Data.types(sch) == (Int64, Union{String, Missing}, String, Union{Float64, Missing}, Float64, Union{Date, Missing}, DateTime, Missing)
@test sink[:id] == [1,2,3,4,5]
@test DataStreams.Data.header(sch) == ["id", "firstname", "lastname", "salary",
"rate", "hired", "fired", "reserved"]
@test DataStreams.Data.types(sch) == (Int64, Union{String, Missing}, String,
Union{Float64, Missing}, Float64,
Union{Date, Missing}, DateTime, Missing)
@test sink[:id] == [1:5;]

# test DataFrameStream creation
dfs = DataFrame(sch)
Expand Down

0 comments on commit a0d44f6

Please sign in to comment.