From a0d44f6f4905d70b69d61654b2687de3197c5ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 3 Oct 2018 21:20:24 +0200 Subject: [PATCH] Re-enable tests of LaTeXStrings and minor code layout fixes --- test/io.jl | 82 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/test/io.jl b/test/io.jl index 26208f1f4f..18de75154e 100644 --- a/test/io.jl +++ b/test/io.jl @@ -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 @@ -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)