From 273bbb32a567802dd52b6c88ab89a8a09742d219 Mon Sep 17 00:00:00 2001 From: nritchie Date: Mon, 3 Aug 2020 11:03:08 -0400 Subject: [PATCH 01/36] Adding support for rich display of Markdown cells --- Project.toml | 1 + src/DataFrames.jl | 1 + src/abstractdataframe/io.jl | 10 +++++++- test/io.jl | 50 ++++++++++++++++++++++++++----------- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Project.toml b/Project.toml index bbd8a70596..0183ac8c1c 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" Future = "9fa8497b-333b-5362-9e8d-4d0656e87820" InvertedIndices = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" +Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" diff --git a/src/DataFrames.jl b/src/DataFrames.jl index 8b64cafc85..4eab7b0de5 100644 --- a/src/DataFrames.jl +++ b/src/DataFrames.jl @@ -5,6 +5,7 @@ using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays @reexport using CategoricalArrays, Missings, InvertedIndices using Base.Sort, Base.Order, Base.Iterators using TableTraits, IteratorInterfaceExtensions +using Markdown import DataAPI, DataAPI.All, diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index f8c4ec4e51..8b2cdb948a 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -142,6 +142,10 @@ function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; cell_val = df[row, column_name] if ismissing(cell_val) write(io, "missing") + elseif cell_val isa Markdown.MD + write(io, "") + show(io, "text/html", cell_val) + write(io, "") elseif cell_val isa SHOW_TABULAR_TYPES write(io, "") cell = sprint(ourshow, cell_val) @@ -303,6 +307,8 @@ function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; cell = df[row,col] if ismissing(cell) print(io, "\\emph{missing}") + elseif cell isa Markdown.MD + show(io, "text/latex", cell) elseif cell isa SHOW_TABULAR_TYPES print(io, "\\emph{") print(io, latex_escape(sprint(ourshow, cell, context=io))) @@ -417,7 +423,9 @@ function printtable(io::IO, elseif isnothing(df[i, j]) print(io, nothingstring) else - if ! (etypes[j] <: Real) + if etypes[j] isa Markdown.MD + show(io, "text/plain", df[i,j]) + elseif ! (etypes[j] <: Real) print(io, quotemark) escapedprint(io, df[i, j], quotestr) print(io, quotemark) diff --git a/test/io.jl b/test/io.jl index 0e9ea5bb64..a492250872 100644 --- a/test/io.jl +++ b/test/io.jl @@ -1,6 +1,6 @@ module TestIO -using Test, DataFrames, CategoricalArrays, Dates +using Test, DataFrames, CategoricalArrays, Dates, Markdown # Test LaTeX export @testset "LaTeX export" begin @@ -9,20 +9,21 @@ using Test, DataFrames, CategoricalArrays, Dates C = ["A", "B", "C", "S"], D = [1.0, 2.0, missing, 3.0], E = CategoricalArray(["a", missing, "c", "d"]), - F = Vector{String}(undef, 4) + F = Vector{String}(undef, 4), + G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) - str = """ - \\begin{tabular}{r|cccccc} - \t& A & B & C & D & E & F\\\\ - \t\\hline - \t& $(Int) & String & String & Float64? & Cat…? & String\\\\ - \t\\hline - \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} \\\\ - \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} \\\\ - \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} \\\\ - \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} \\\\ - \\end{tabular} - """ + str = + "\\begin{tabular}{r|ccccccc}\n" * + "\t& A & B & C & D & E & F & G\\\\\n" * + "\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\\n" * + "\t\\hline\n" * + "\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\\n" * + "\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\\n" * + "\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\\n" * + "\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\\n" * + "\\end{tabular}\n" + + @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str @test repr(MIME("text/latex"), eachrow(df)) == str @@ -130,6 +131,27 @@ end @test_throws ArgumentError DataFrames._show(stdout, MIME("text/html"), DataFrame(ones(2,2)), rowid=10) + + df = DataFrame( + A=[1,4,9,16], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"###A", + md"``\frac{A}{B}``", + md"*A*b**A**" ] + ) + + @test repr(MIME("text/html"), df) == + "" * + "

4 rows × 2 columns

" * + "" * + "
AB
Int64MD…
11
" * + "

DataFrames.jl" * + "

\n
24
" * + "

###A

\n
39
" * + "

$\\frac{A}{B}$

\n
416

AbA

"* + "\n
" + end # test limit attribute of IOContext is used From e72d03365cb0137846c033209ee10f0f79277deb Mon Sep 17 00:00:00 2001 From: nritchie Date: Tue, 4 Aug 2020 11:14:18 -0400 Subject: [PATCH 02/36] Fixing Markdown as "text/csv" and "text/plain" --- src/abstractdataframe/io.jl | 7 ++-- src/abstractdataframe/show.jl | 5 +++ test/io.jl | 64 ++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index 8b2cdb948a..bd6047c2f9 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -423,8 +423,11 @@ function printtable(io::IO, elseif isnothing(df[i, j]) print(io, nothingstring) else - if etypes[j] isa Markdown.MD - show(io, "text/plain", df[i,j]) + if df[i,j] isa Markdown.MD + print(io, quotemark) + r=repr(df[i,j]) + escapedprint(io, first(r,max(0,length(r)-1)), quotestr) + print(io, quotemark) elseif ! (etypes[j] <: Real) print(io, quotemark) escapedprint(io, df[i, j], quotestr) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 85ba621c30..708647f345 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -54,6 +54,11 @@ ourshow(io::IO, x::Symbol) = ourshow(io, string(x)) ourshow(io::IO, x::Nothing; styled::Bool=false) = ourshow(io, "", styled=styled) ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = ourshow(io, summary(x), styled=styled) +function ourshow(io::IO, x::Markdown.MD) + r = repr(x) + len = min(something(findfirst(c->c=='\n', r), length(r) + 1) - 1, 50) + return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) +end # AbstractChar: https://github.com/JuliaLang/julia/pull/34730 (1.5.0-DEV.261) # Irrational: https://github.com/JuliaLang/julia/pull/34741 (1.5.0-DEV.266) diff --git a/test/io.jl b/test/io.jl index a492250872..7b29bd501c 100644 --- a/test/io.jl +++ b/test/io.jl @@ -15,7 +15,7 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown str = "\\begin{tabular}{r|ccccccc}\n" * "\t& A & B & C & D & E & F & G\\\\\n" * - "\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\\n" * + "\t\\hline\n\t& "*repr(Int)*" & String & String & Float64? & Cat…? & String & MD…\\\\\n" * "\t\\hline\n" * "\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\\n" * "\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\\n" * @@ -202,6 +202,68 @@ end end end +@testset "Markdown as text/plain and as text/csv" begin + df = DataFrame( + A=Int64[1,4,9,16,25], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"``\frac{x^2}{x^2+y^2}``", + md"# Header", + md"This is *very*, **very**, very, very, very, very, very, very, very long line" , + md""] + ) + @test sprint(show, "text/plain", df) == + "5×2 DataFrame\n" * + "│ Row │ A │ B │\n" * + "│ │ Int64 │ Markdown.MD │\n" * + "├─────┼───────┼─────────────────────────────────────────────────────┤\n" * + "│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │\n" * + "│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │\n" * + "│ 3 │ 9 │ # Header │\n" * + "│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │\n" * + "│ 5 │ 25 │ │" + @test sprint(show, "text/csv", df) == + "\"A\",\"B\"\n"* + "1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\"\n"* + "4,\"\$\\\\frac{x^2}{x^2+y^2}\$\"\n"* + "9,\"# Header\"\n"* + "16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\"\n"* + "25,\"\"\n" +end + +@testset "Markdown as HTML" begin + df = DataFrame( + A=Int64[1,4,9,16,25], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"``\frac{x^2}{x^2+y^2}``", + Markdown.parse("# Multi-line\nThis is a multi-line\n\n**Markdown**"), + md"This is *very*, **very**, very, very, very, very, very, very, very long line" , + md"" + ] + ) + @test sprint(show,"text/html",df) == + ""* + "" * + "" * + "

5 rows × 2 columns

" * + "" * + "" * + "" * + "" * + "
AB
Int64MD…
11" * + "" * + "
24" * + "

$\\frac{x^2}{x^2+y^2}$

\n
" * + "
39

Multi-line

\n" * + "

This is a multi-line

\n" * + "

Markdown

\n" * + "
416" * + "

This is very, very, very, very, very," * + " very, very, very, very long line

\n" * + "
525
" +end + @testset "empty data frame and DataFrameRow" begin df = DataFrame(a = [1,2], b = [1.0, 2.0]) From a1d9619dd2b821ceb68447abe48763370185e4c3 Mon Sep 17 00:00:00 2001 From: nritchie Date: Tue, 4 Aug 2020 19:18:51 -0400 Subject: [PATCH 03/36] Fix test error in Markdown to HTML in 32-bit systems --- test/io.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/io.jl b/test/io.jl index 7b29bd501c..2356e835bb 100644 --- a/test/io.jl +++ b/test/io.jl @@ -133,7 +133,7 @@ end DataFrame(ones(2,2)), rowid=10) df = DataFrame( - A=[1,4,9,16], + A=Int64[1,4,9,16], B = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", From 57a3b5868fd27a926a1a256b98f3c72cbd5dbae5 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 6 Aug 2020 11:55:43 -0400 Subject: [PATCH 04/36] Fixing show and adding multi-codepoint tests --- src/abstractdataframe/show.jl | 2 +- test/io.jl | 125 +++++++++++++++++++++------------- 2 files changed, 80 insertions(+), 47 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 708647f345..6c3fbfccf6 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -56,7 +56,7 @@ ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = ourshow(io, summary(x), styled=styled) function ourshow(io::IO, x::Markdown.MD) r = repr(x) - len = min(something(findfirst(c->c=='\n', r), length(r) + 1) - 1, 50) + len = min(length(r, 1, something(findfirst(c->c=='\n', r), lastindex(r)+1)-1), 50) return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) end diff --git a/test/io.jl b/test/io.jl index 2356e835bb..5702b2b72c 100644 --- a/test/io.jl +++ b/test/io.jl @@ -204,64 +204,97 @@ end @testset "Markdown as text/plain and as text/csv" begin df = DataFrame( - A=Int64[1,4,9,16,25], + A=Int64[1,4,9,16,25,36,49,64], B = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"``\frac{x^2}{x^2+y^2}``", md"# Header", md"This is *very*, **very**, very, very, very, very, very, very, very long line" , - md""] + md"", + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" * + "∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"* + " * ∞7∫αγ\n"* + " * ∞8∫αγ\n"* + " * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* + " * γ∞1∫α\n"* + " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + ] ) - @test sprint(show, "text/plain", df) == - "5×2 DataFrame\n" * - "│ Row │ A │ B │\n" * - "│ │ Int64 │ Markdown.MD │\n" * - "├─────┼───────┼─────────────────────────────────────────────────────┤\n" * - "│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │\n" * - "│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │\n" * - "│ 3 │ 9 │ # Header │\n" * - "│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │\n" * - "│ 5 │ 25 │ │" - @test sprint(show, "text/csv", df) == - "\"A\",\"B\"\n"* - "1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\"\n"* - "4,\"\$\\\\frac{x^2}{x^2+y^2}\$\"\n"* - "9,\"# Header\"\n"* - "16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\"\n"* - "25,\"\"\n" + @test sprint(show, "text/plain", df) == """ +8×2 DataFrame +│ Row │ A │ B │ +│ │ Int64 │ Markdown.MD │ +├─────┼───────┼─────────────────────────────────────────────────────┤ +│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │ +│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ +│ 3 │ 9 │ # Header │ +│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │ +│ 5 │ 25 │ │ +│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │ +│ 7 │ 49 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ… │ +│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │""" + + @test sprint(show, "text/csv", df) == """ +\"A\",\"B\" +1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" +4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" +9,\"# Header\" +16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" +25,\"\" +36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +49,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\\n\\n * ∞7∫αγ\\n * ∞8∫αγ\\n * ∞9∫αγ∞0∫α\\n\\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +""" end @testset "Markdown as HTML" begin df = DataFrame( - A=Int64[1,4,9,16,25], - B = [ - md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", - md"``\frac{x^2}{x^2+y^2}``", - Markdown.parse("# Multi-line\nThis is a multi-line\n\n**Markdown**"), - md"This is *very*, **very**, very, very, very, very, very, very, very long line" , - md"" - ] + A=Int64[1,4,9,16,25,36,49,64], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"``\frac{x^2}{x^2+y^2}``", + md"# Header", + md"This is *very*, **very**, very, very, very, very, very, very, very long line" , + md"", + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" * + "∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"* + " * ∞7∫αγ\n"* + " * ∞8∫αγ\n"* + " * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* + " * γ∞1∫α\n"* + " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + ] ) @test sprint(show,"text/html",df) == - ""* - "" * - "" * - "

5 rows × 2 columns

" * - "" * - "" * - "" * - "" * - "
AB
Int64MD…
11" * - "" * - "
24" * - "

$\\frac{x^2}{x^2+y^2}$

\n
" * - "
39

Multi-line

\n" * - "

This is a multi-line

\n" * - "

Markdown

\n" * - "
416" * - "

This is very, very, very, very, very," * - " very, very, very, very long line

\n" * - "
525
" + "" * + "" * + "" * + "" * + "" * "

8 rows × 2 columns

" * + "" * + "" * + "" * + "" * + "" * + "" * + "" * + "
AB
Int64MD…
11
" * + "

DataFrames.jl

\n
24

$\\frac{x^2}{x^2+y^2}$

\n
39

Header

\n
416
" * + "

This is very, very, very, very, very, very, very, very, very long line

\n" * + "
525
636
" * + "

∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0

\n" * + "
749
" * + "

∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ

\n
    \n
  • ∞7∫αγ

    \n
  • \n
  • ∞8∫αγ

    \n
  • \n
  • ∞9∫αγ∞0∫α

    \n
  • \n
\n

γ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0

\n" * + "
864
" * + "

∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α

" * + "\n
    \n" * + "
  • γ∞1∫α

    \n
  • \n" * + "
  • γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0

    \n
  • \n" * + "
\n" * "
" end @testset "empty data frame and DataFrameRow" begin From 531e089c9c9e8efeb329dc947be88d4e3f487003 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 6 Aug 2020 17:55:44 -0400 Subject: [PATCH 05/36] 32 it is... --- src/abstractdataframe/show.jl | 2 +- test/io.jl | 37 +++++++++++++++++------------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 6c3fbfccf6..af36f941c9 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -56,7 +56,7 @@ ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = ourshow(io, summary(x), styled=styled) function ourshow(io::IO, x::Markdown.MD) r = repr(x) - len = min(length(r, 1, something(findfirst(c->c=='\n', r), lastindex(r)+1)-1), 50) + len = min(length(r, 1, something(findfirst(==('\n'), r), lastindex(r)+1)-1), 32) return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) end diff --git a/test/io.jl b/test/io.jl index 5702b2b72c..7858ceaa8e 100644 --- a/test/io.jl +++ b/test/io.jl @@ -211,12 +211,11 @@ end md"# Header", md"This is *very*, **very**, very, very, very, very, very, very, very long line" , md"", - Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" * - "∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), - Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"* - " * ∞7∫αγ\n"* - " * ∞8∫αγ\n"* - " * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3"), + Markdown.parse("∫αγ∞1∫αγ∞\n"* + " * 2∫αγ∞3∫αγ∞4\n"* + " * ∫αγ∞5∫αγ\n"* + " * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* " * γ∞1∫α\n"* " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), @@ -224,17 +223,17 @@ end ) @test sprint(show, "text/plain", df) == """ 8×2 DataFrame -│ Row │ A │ B │ -│ │ Int64 │ Markdown.MD │ -├─────┼───────┼─────────────────────────────────────────────────────┤ -│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │ -│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ -│ 3 │ 9 │ # Header │ -│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │ -│ 5 │ 25 │ │ -│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │ -│ 7 │ 49 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ… │ -│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │""" +│ Row │ A │ B │ +│ │ Int64 │ Markdown.MD │ +├─────┼───────┼───────────────────────────────────┤ +│ 1 │ 1 │ [DataFrames.jl](http://juliadata… │ +│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ +│ 3 │ 9 │ # Header │ +│ 4 │ 16 │ This is *very*, **very**, very, … │ +│ 5 │ 25 │ │ +│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │ +│ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ +│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" @test sprint(show, "text/csv", df) == """ \"A\",\"B\" @@ -243,8 +242,8 @@ end 9,\"# Header\" 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" 25,\"\" -36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" -49,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\\n\\n * ∞7∫αγ\\n * ∞8∫αγ\\n * ∞9∫αγ∞0∫α\\n\\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" +49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" """ end From ea571e633592993c8434c860ace2a8192c82866f Mon Sep 17 00:00:00 2001 From: Nicholas Ritchie Date: Fri, 7 Aug 2020 08:06:51 -0400 Subject: [PATCH 06/36] Use chomp to remove trailing '\n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bogumił Kamiński --- src/abstractdataframe/io.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index bd6047c2f9..e0d039ccf6 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -426,7 +426,7 @@ function printtable(io::IO, if df[i,j] isa Markdown.MD print(io, quotemark) r=repr(df[i,j]) - escapedprint(io, first(r,max(0,length(r)-1)), quotestr) + escapedprint(io, chomp(r), quotestr) print(io, quotemark) elseif ! (etypes[j] <: Real) print(io, quotemark) From c53598e44d9fbd03c5c8a0f9a5ffa5e369b22530 Mon Sep 17 00:00:00 2001 From: nritchie Date: Mon, 24 Aug 2020 16:31:57 -0400 Subject: [PATCH 07/36] Fixing conflicts --- Project.toml | 1 + src/DataFrames.jl | 1 + 2 files changed, 2 insertions(+) diff --git a/Project.toml b/Project.toml index 0183ac8c1c..93a59974f3 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" Future = "9fa8497b-333b-5362-9e8d-4d0656e87820" InvertedIndices = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" diff --git a/src/DataFrames.jl b/src/DataFrames.jl index 4eab7b0de5..81dbfe84f8 100644 --- a/src/DataFrames.jl +++ b/src/DataFrames.jl @@ -6,6 +6,7 @@ using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays using Base.Sort, Base.Order, Base.Iterators using TableTraits, IteratorInterfaceExtensions using Markdown +import LinearAlgebra: norm import DataAPI, DataAPI.All, From a391912e26cd6b0df9aa991cb210c5a0a6f2a09a Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Mon, 24 Aug 2020 16:58:13 -0600 Subject: [PATCH 08/36] Don't match on AbstractVector type parameter due to compiler crash (#2383) --- Project.toml | 2 +- src/groupeddataframe/splitapplycombine.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index d3bee6ff1e..4d8bc8321c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DataFrames" uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -version = "0.21.6" +version = "0.21.7" [deps] CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" diff --git a/src/groupeddataframe/splitapplycombine.jl b/src/groupeddataframe/splitapplycombine.jl index 078b61320f..9ee7c22247 100644 --- a/src/groupeddataframe/splitapplycombine.jl +++ b/src/groupeddataframe/splitapplycombine.jl @@ -969,7 +969,7 @@ function copyto_widen!(res::AbstractVector{T}, x::AbstractVector) where T end function groupreduce!(res::AbstractVector, f, op, condf, adjust, checkempty::Bool, - incol::AbstractVector{T}, gd::GroupedDataFrame) where {T} + incol::AbstractVector, gd::GroupedDataFrame) n = length(gd) if adjust !== nothing || checkempty counts = zeros(Int, n) @@ -1001,7 +1001,7 @@ function groupreduce!(res::AbstractVector, f, op, condf, adjust, checkempty::Boo end @inbounds for gix in eachindex(res) if !isassigned(res, gix) - res[gix] = initf(nonmissingtype(T)) + res[gix] = initf(nonmissingtype(eltype(incol))) end end end From 5f5f12192f533a4dae337e76eaa0474f937eab1e Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Tue, 25 Aug 2020 11:38:20 -0400 Subject: [PATCH 09/36] Pulling df[i,j] out and optimizing ourshow. --- src/abstractdataframe/io.jl | 13 +++++++------ src/abstractdataframe/show.jl | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index e0d039ccf6..5d5fa7c1fb 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -418,22 +418,23 @@ function printtable(io::IO, quotestr = string(quotemark) for i in 1:n for j in 1:p - if ismissing(df[i, j]) + cell = df[i, j] + if ismissing(cell) print(io, missingstring) - elseif isnothing(df[i, j]) + elseif isnothing(cell) print(io, nothingstring) else - if df[i,j] isa Markdown.MD + if cell isa Markdown.MD print(io, quotemark) - r=repr(df[i,j]) + r = repr(cell) escapedprint(io, chomp(r), quotestr) print(io, quotemark) elseif ! (etypes[j] <: Real) print(io, quotemark) - escapedprint(io, df[i, j], quotestr) + escapedprint(io, cell, quotestr) print(io, quotemark) else - print(io, df[i, j]) + print(io, cell) end end if j < p diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index af36f941c9..4bbc203943 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -57,7 +57,7 @@ ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = function ourshow(io::IO, x::Markdown.MD) r = repr(x) len = min(length(r, 1, something(findfirst(==('\n'), r), lastindex(r)+1)-1), 32) - return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) + return print(io, len < length(r) - 1 ? first(r, len)*'…' : first(r, len)) end # AbstractChar: https://github.com/JuliaLang/julia/pull/34730 (1.5.0-DEV.261) From 3a85fbf1bfd205d8a6233473900e24caf7f5cea6 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Tue, 25 Aug 2020 12:13:41 -0400 Subject: [PATCH 10/36] Formatting improvements --- test/io.jl | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/io.jl b/test/io.jl index 7858ceaa8e..7cfe0f39c3 100644 --- a/test/io.jl +++ b/test/io.jl @@ -4,7 +4,7 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown # Test LaTeX export @testset "LaTeX export" begin - df = DataFrame(A = 1:4, + df = DataFrame(A = convert.( Int64, 1:4), B = ["\$10.0", "M&F", "A~B", "\\alpha"], C = ["A", "B", "C", "S"], D = [1.0, 2.0, missing, 3.0], @@ -12,17 +12,16 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown F = Vector{String}(undef, 4), G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) - str = - "\\begin{tabular}{r|ccccccc}\n" * - "\t& A & B & C & D & E & F & G\\\\\n" * - "\t\\hline\n\t& "*repr(Int)*" & String & String & Float64? & Cat…? & String & MD…\\\\\n" * - "\t\\hline\n" * - "\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\\n" * - "\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\\n" * - "\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\\n" * - "\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\\n" * - "\\end{tabular}\n" - + str = """ + \\begin{tabular}{r|ccccccc} + \t& A & B & C & D & E & F & G\\\\ + \t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ + \t\\hline + \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ + \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ + \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ + \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ + \\end{tabular}\n""" @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str From 8928695a27cb79074e1a87c3245a08b72503e8cd Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Tue, 25 Aug 2020 12:16:08 -0400 Subject: [PATCH 11/36] Additional formatting improvements --- test/io.jl | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/io.jl b/test/io.jl index 7cfe0f39c3..1771ffe672 100644 --- a/test/io.jl +++ b/test/io.jl @@ -221,30 +221,30 @@ end ] ) @test sprint(show, "text/plain", df) == """ -8×2 DataFrame -│ Row │ A │ B │ -│ │ Int64 │ Markdown.MD │ -├─────┼───────┼───────────────────────────────────┤ -│ 1 │ 1 │ [DataFrames.jl](http://juliadata… │ -│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ -│ 3 │ 9 │ # Header │ -│ 4 │ 16 │ This is *very*, **very**, very, … │ -│ 5 │ 25 │ │ -│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │ -│ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ -│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" + 8×2 DataFrame + │ Row │ A │ B │ + │ │ Int64 │ Markdown.MD │ + ├─────┼───────┼───────────────────────────────────┤ + │ 1 │ 1 │ [DataFrames.jl](http://juliadata… │ + │ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ + │ 3 │ 9 │ # Header │ + │ 4 │ 16 │ This is *very*, **very**, very, … │ + │ 5 │ 25 │ │ + │ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │ + │ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ + │ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" @test sprint(show, "text/csv", df) == """ -\"A\",\"B\" -1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" -4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" -9,\"# Header\" -16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" -25,\"\" -36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" -49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" -64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" -""" + \"A\",\"B\" + 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" + 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" + 9,\"# Header\" + 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" + 25,\"\" + 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" + 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + """ end @testset "Markdown as HTML" begin From 1a0fd3baf380cad67ff0707139417b1819500000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 27 Aug 2020 16:32:02 +0200 Subject: [PATCH 12/36] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2162fed4fa..62b58061ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ Thanks for taking the plunge! or related issues for context, before opening a new issue * Including minimal examples is greatly appreciated * If it's a bug, or unexpected behaviour, reproducing on the latest development version - (`Pkg.checkout("DataFrames")`) is a good gut check and can streamline the process, + (`Pkg.develop("DataFrames")`) is a good gut check and can streamline the process, along with including the first two lines of output from `versioninfo()` ## Contributing From c1e38d4e8e33e26007bd22a2628542962d533377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 27 Aug 2020 16:39:29 +0200 Subject: [PATCH 13/36] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62b58061ac..031e9d1e11 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ Thanks for taking the plunge! or related issues for context, before opening a new issue * Including minimal examples is greatly appreciated * If it's a bug, or unexpected behaviour, reproducing on the latest development version - (`Pkg.develop("DataFrames")`) is a good gut check and can streamline the process, + (`Pkg.add(name="DataFrames", rev="master")`) is a good gut check and can streamline the process, along with including the first two lines of output from `versioninfo()` ## Contributing From be358523a01169a75b597159c0b45e3246ad2985 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 27 Aug 2020 12:07:24 -0400 Subject: [PATCH 14/36] Fixing triple-quoted strings in 1.0.X --- test/io.jl | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/test/io.jl b/test/io.jl index 1771ffe672..5149099f26 100644 --- a/test/io.jl +++ b/test/io.jl @@ -4,7 +4,7 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown # Test LaTeX export @testset "LaTeX export" begin - df = DataFrame(A = convert.( Int64, 1:4), + df = DataFrame(A = Int64.( 1:4 ), B = ["\$10.0", "M&F", "A~B", "\\alpha"], C = ["A", "B", "C", "S"], D = [1.0, 2.0, missing, 3.0], @@ -13,15 +13,16 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) str = """ - \\begin{tabular}{r|ccccccc} - \t& A & B & C & D & E & F & G\\\\ - \t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ - \t\\hline - \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ - \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ - \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ - \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ - \\end{tabular}\n""" +\\begin{tabular}{r|ccccccc} +\t& A & B & C & D & E & F & G\\\\ +\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ +\t\\hline +\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ +\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ +\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ +\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ +\\end{tabular} +""" @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str @@ -234,17 +235,18 @@ end │ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ │ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" - @test sprint(show, "text/csv", df) == """ - \"A\",\"B\" - 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" - 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" - 9,\"# Header\" - 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" - 25,\"\" - 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" - 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - """ + @test sprint(show, "text/csv", df) == + """ + \"A\",\"B\" + 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" + 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" + 9,\"# Header\" + 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" + 25,\"\" + 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" + 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + """ end @testset "Markdown as HTML" begin From 7d4e5d0fae3e65726b0cd057fe344e2c7283ecb1 Mon Sep 17 00:00:00 2001 From: Nicholas Ritchie Date: Thu, 27 Aug 2020 12:09:35 -0400 Subject: [PATCH 15/36] Strip space in test case Co-authored-by: Milan Bouchet-Valat --- test/io.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/io.jl b/test/io.jl index 5149099f26..aaeb903e9f 100644 --- a/test/io.jl +++ b/test/io.jl @@ -213,12 +213,12 @@ end md"", Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3"), Markdown.parse("∫αγ∞1∫αγ∞\n"* - " * 2∫αγ∞3∫αγ∞4\n"* - " * ∫αγ∞5∫αγ\n"* - " * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + " * 2∫αγ∞3∫αγ∞4\n"* + " * ∫αγ∞5∫αγ\n"* + " * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* - " * γ∞1∫α\n"* - " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + " * γ∞1∫α\n"* + " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), ] ) @test sprint(show, "text/plain", df) == """ From 2f5c2d35e129c80797d0164228b2143c883e1779 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 27 Aug 2020 16:57:30 -0400 Subject: [PATCH 16/36] Using @nalimilan suggestion --- test/io.jl | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/test/io.jl b/test/io.jl index 5149099f26..e7946f1851 100644 --- a/test/io.jl +++ b/test/io.jl @@ -13,16 +13,25 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) str = """ -\\begin{tabular}{r|ccccccc} -\t& A & B & C & D & E & F & G\\\\ -\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ -\t\\hline -\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ -\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ -\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ -\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ -\\end{tabular} -""" + \\begin{tabular}{r|ccccccc} + \t& A & B & C & D & E & F & G\\\\ + \t\\hline + \t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ + \t\\hline + \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl} + + \\\\ + \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A + + \\\\ + \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$ + + \\\\ + \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A} + + \\\\ + \\end{tabular} + """ @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str @@ -235,18 +244,18 @@ end │ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ │ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" - @test sprint(show, "text/csv", df) == - """ - \"A\",\"B\" - 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" - 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" - 9,\"# Header\" - 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" - 25,\"\" - 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" - 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - """ + @test sprint(show, "text/csv", df) == + """ + \"A\",\"B\" + 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" + 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" + 9,\"# Header\" + 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" + 25,\"\" + 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" + 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + """ end @testset "Markdown as HTML" begin From b90696d8f06cba7f958c5f28f851d6c8f3f4633e Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Fri, 28 Aug 2020 08:30:38 -0400 Subject: [PATCH 17/36] Improving LaTeX output appearance, NEWS.md entry --- NEWS.md | 2 ++ src/abstractdataframe/io.jl | 2 +- test/io.jl | 16 ++++------------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index 135e857113..c8a65badd1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,6 +42,8 @@ ([#2373](https://github.com/JuliaData/DataFrames.jl/pull/2373)) * add `columnindex` for `DataFrameRow` ([#2380](https://github.com/JuliaData/DataFrames.jl/pull/2380)) +* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX + ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) ## Deprecated diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index d5f294184e..eda9a60200 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -307,7 +307,7 @@ function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; if ismissing(cell) print(io, "\\emph{missing}") elseif cell isa Markdown.MD - show(io, "text/latex", cell) + print(io, strip(repr(MIME("text/latex"), cell))) elseif cell isa SHOW_TABULAR_TYPES print(io, "\\emph{") print(io, latex_escape(sprint(ourshow, cell, context=io))) diff --git a/test/io.jl b/test/io.jl index b36d48c722..83065b6a90 100644 --- a/test/io.jl +++ b/test/io.jl @@ -18,18 +18,10 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown \t\\hline \t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ \t\\hline - \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl} - - \\\\ - \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A - - \\\\ - \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$ - - \\\\ - \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A} - - \\\\ + \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl} \\\\ + \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A \\\\ + \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$ \\\\ + \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A} \\\\ \\end{tabular} """ From 606f3ebf4503b51f0e7354eb6b92a58d5740b060 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Fri, 28 Aug 2020 08:34:10 -0400 Subject: [PATCH 18/36] Moved NEWS.md item to "Other relevant changes" section. --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index c8a65badd1..dd303bf6eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,8 +42,6 @@ ([#2373](https://github.com/JuliaData/DataFrames.jl/pull/2373)) * add `columnindex` for `DataFrameRow` ([#2380](https://github.com/JuliaData/DataFrames.jl/pull/2380)) -* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX - ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) ## Deprecated @@ -57,3 +55,5 @@ * Documentation is now available also in *Dark* mode ([#2315](https://github.com/JuliaData/DataFrames.jl/pull/2315)) +* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX + ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) From 174d632f4c677552ed6a669b3f8d9ec83f6d3db9 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Fri, 28 Aug 2020 08:52:59 -0400 Subject: [PATCH 19/36] Correct NEWS.md item on rich display support --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index dd303bf6eb..f96081a08f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -55,5 +55,5 @@ * Documentation is now available also in *Dark* mode ([#2315](https://github.com/JuliaData/DataFrames.jl/pull/2315)) -* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX +* add rich display support for Markdown cell entries in HTML and LaTeX ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) From 541403166ed5ec4f567e8c80b84d5d549ce59745 Mon Sep 17 00:00:00 2001 From: nritchie Date: Mon, 3 Aug 2020 11:03:08 -0400 Subject: [PATCH 20/36] Adding support for rich display of Markdown cells --- Project.toml | 1 + src/DataFrames.jl | 1 + src/abstractdataframe/io.jl | 10 +++++++- test/io.jl | 50 ++++++++++++++++++++++++++----------- 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Project.toml b/Project.toml index 4d8bc8321c..80cb062e3c 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ Future = "9fa8497b-333b-5362-9e8d-4d0656e87820" InvertedIndices = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" PooledArrays = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" diff --git a/src/DataFrames.jl b/src/DataFrames.jl index a8e5bf9b60..f278e702f8 100644 --- a/src/DataFrames.jl +++ b/src/DataFrames.jl @@ -6,6 +6,7 @@ using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays using Base.Sort, Base.Order, Base.Iterators using TableTraits, IteratorInterfaceExtensions import LinearAlgebra: norm +using Markdown import DataAPI, DataAPI.All, diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index 8c999fd8d7..268604b9f0 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -142,6 +142,10 @@ function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; cell_val = df[row, column_name] if ismissing(cell_val) write(io, "missing") + elseif cell_val isa Markdown.MD + write(io, "") + show(io, "text/html", cell_val) + write(io, "") elseif cell_val isa SHOW_TABULAR_TYPES write(io, "") cell = sprint(ourshow, cell_val) @@ -302,6 +306,8 @@ function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; cell = df[row,col] if ismissing(cell) print(io, "\\emph{missing}") + elseif cell isa Markdown.MD + show(io, "text/latex", cell) elseif cell isa SHOW_TABULAR_TYPES print(io, "\\emph{") print(io, latex_escape(sprint(ourshow, cell, context=io))) @@ -415,7 +421,9 @@ function printtable(io::IO, elseif isnothing(df[i, j]) print(io, nothingstring) else - if ! (etypes[j] <: Real) + if etypes[j] isa Markdown.MD + show(io, "text/plain", df[i,j]) + elseif ! (etypes[j] <: Real) print(io, quotemark) escapedprint(io, df[i, j], quotestr) print(io, quotemark) diff --git a/test/io.jl b/test/io.jl index 0e9ea5bb64..a492250872 100644 --- a/test/io.jl +++ b/test/io.jl @@ -1,6 +1,6 @@ module TestIO -using Test, DataFrames, CategoricalArrays, Dates +using Test, DataFrames, CategoricalArrays, Dates, Markdown # Test LaTeX export @testset "LaTeX export" begin @@ -9,20 +9,21 @@ using Test, DataFrames, CategoricalArrays, Dates C = ["A", "B", "C", "S"], D = [1.0, 2.0, missing, 3.0], E = CategoricalArray(["a", missing, "c", "d"]), - F = Vector{String}(undef, 4) + F = Vector{String}(undef, 4), + G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) - str = """ - \\begin{tabular}{r|cccccc} - \t& A & B & C & D & E & F\\\\ - \t\\hline - \t& $(Int) & String & String & Float64? & Cat…? & String\\\\ - \t\\hline - \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} \\\\ - \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} \\\\ - \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} \\\\ - \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} \\\\ - \\end{tabular} - """ + str = + "\\begin{tabular}{r|ccccccc}\n" * + "\t& A & B & C & D & E & F & G\\\\\n" * + "\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\\n" * + "\t\\hline\n" * + "\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\\n" * + "\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\\n" * + "\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\\n" * + "\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\\n" * + "\\end{tabular}\n" + + @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str @test repr(MIME("text/latex"), eachrow(df)) == str @@ -130,6 +131,27 @@ end @test_throws ArgumentError DataFrames._show(stdout, MIME("text/html"), DataFrame(ones(2,2)), rowid=10) + + df = DataFrame( + A=[1,4,9,16], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"###A", + md"``\frac{A}{B}``", + md"*A*b**A**" ] + ) + + @test repr(MIME("text/html"), df) == + "" * + "

4 rows × 2 columns

" * + "" * + "
AB
Int64MD…
11
" * + "

DataFrames.jl" * + "

\n
24
" * + "

###A

\n
39
" * + "

$\\frac{A}{B}$

\n
416

AbA

"* + "\n
" + end # test limit attribute of IOContext is used From 17b6e1b6ca978e62ea0a570629749f7ee70ed786 Mon Sep 17 00:00:00 2001 From: nritchie Date: Tue, 4 Aug 2020 11:14:18 -0400 Subject: [PATCH 21/36] Fixing Markdown as "text/csv" and "text/plain" --- src/abstractdataframe/io.jl | 7 ++-- src/abstractdataframe/show.jl | 5 +++ test/io.jl | 64 ++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index 268604b9f0..5b4c17b69c 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -421,8 +421,11 @@ function printtable(io::IO, elseif isnothing(df[i, j]) print(io, nothingstring) else - if etypes[j] isa Markdown.MD - show(io, "text/plain", df[i,j]) + if df[i,j] isa Markdown.MD + print(io, quotemark) + r=repr(df[i,j]) + escapedprint(io, first(r,max(0,length(r)-1)), quotestr) + print(io, quotemark) elseif ! (etypes[j] <: Real) print(io, quotemark) escapedprint(io, df[i, j], quotestr) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 85ba621c30..708647f345 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -54,6 +54,11 @@ ourshow(io::IO, x::Symbol) = ourshow(io, string(x)) ourshow(io::IO, x::Nothing; styled::Bool=false) = ourshow(io, "", styled=styled) ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = ourshow(io, summary(x), styled=styled) +function ourshow(io::IO, x::Markdown.MD) + r = repr(x) + len = min(something(findfirst(c->c=='\n', r), length(r) + 1) - 1, 50) + return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) +end # AbstractChar: https://github.com/JuliaLang/julia/pull/34730 (1.5.0-DEV.261) # Irrational: https://github.com/JuliaLang/julia/pull/34741 (1.5.0-DEV.266) diff --git a/test/io.jl b/test/io.jl index a492250872..7b29bd501c 100644 --- a/test/io.jl +++ b/test/io.jl @@ -15,7 +15,7 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown str = "\\begin{tabular}{r|ccccccc}\n" * "\t& A & B & C & D & E & F & G\\\\\n" * - "\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\\n" * + "\t\\hline\n\t& "*repr(Int)*" & String & String & Float64? & Cat…? & String & MD…\\\\\n" * "\t\\hline\n" * "\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\\n" * "\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\\n" * @@ -202,6 +202,68 @@ end end end +@testset "Markdown as text/plain and as text/csv" begin + df = DataFrame( + A=Int64[1,4,9,16,25], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"``\frac{x^2}{x^2+y^2}``", + md"# Header", + md"This is *very*, **very**, very, very, very, very, very, very, very long line" , + md""] + ) + @test sprint(show, "text/plain", df) == + "5×2 DataFrame\n" * + "│ Row │ A │ B │\n" * + "│ │ Int64 │ Markdown.MD │\n" * + "├─────┼───────┼─────────────────────────────────────────────────────┤\n" * + "│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │\n" * + "│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │\n" * + "│ 3 │ 9 │ # Header │\n" * + "│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │\n" * + "│ 5 │ 25 │ │" + @test sprint(show, "text/csv", df) == + "\"A\",\"B\"\n"* + "1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\"\n"* + "4,\"\$\\\\frac{x^2}{x^2+y^2}\$\"\n"* + "9,\"# Header\"\n"* + "16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\"\n"* + "25,\"\"\n" +end + +@testset "Markdown as HTML" begin + df = DataFrame( + A=Int64[1,4,9,16,25], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"``\frac{x^2}{x^2+y^2}``", + Markdown.parse("# Multi-line\nThis is a multi-line\n\n**Markdown**"), + md"This is *very*, **very**, very, very, very, very, very, very, very long line" , + md"" + ] + ) + @test sprint(show,"text/html",df) == + ""* + "" * + "" * + "

5 rows × 2 columns

" * + "" * + "" * + "" * + "" * + "
AB
Int64MD…
11" * + "" * + "
24" * + "

$\\frac{x^2}{x^2+y^2}$

\n
" * + "
39

Multi-line

\n" * + "

This is a multi-line

\n" * + "

Markdown

\n" * + "
416" * + "

This is very, very, very, very, very," * + " very, very, very, very long line

\n" * + "
525
" +end + @testset "empty data frame and DataFrameRow" begin df = DataFrame(a = [1,2], b = [1.0, 2.0]) From 7a8c0de9ba84278841c9a4e533e04c3b032fd8c1 Mon Sep 17 00:00:00 2001 From: nritchie Date: Tue, 4 Aug 2020 19:18:51 -0400 Subject: [PATCH 22/36] Fix test error in Markdown to HTML in 32-bit systems --- test/io.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/io.jl b/test/io.jl index 7b29bd501c..2356e835bb 100644 --- a/test/io.jl +++ b/test/io.jl @@ -133,7 +133,7 @@ end DataFrame(ones(2,2)), rowid=10) df = DataFrame( - A=[1,4,9,16], + A=Int64[1,4,9,16], B = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", From c112ef41f51ef8318c8612624d61ed58be548a04 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 6 Aug 2020 11:55:43 -0400 Subject: [PATCH 23/36] Fixing show and adding multi-codepoint tests --- src/abstractdataframe/show.jl | 2 +- test/io.jl | 125 +++++++++++++++++++++------------- 2 files changed, 80 insertions(+), 47 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 708647f345..6c3fbfccf6 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -56,7 +56,7 @@ ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = ourshow(io, summary(x), styled=styled) function ourshow(io::IO, x::Markdown.MD) r = repr(x) - len = min(something(findfirst(c->c=='\n', r), length(r) + 1) - 1, 50) + len = min(length(r, 1, something(findfirst(c->c=='\n', r), lastindex(r)+1)-1), 50) return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) end diff --git a/test/io.jl b/test/io.jl index 2356e835bb..5702b2b72c 100644 --- a/test/io.jl +++ b/test/io.jl @@ -204,64 +204,97 @@ end @testset "Markdown as text/plain and as text/csv" begin df = DataFrame( - A=Int64[1,4,9,16,25], + A=Int64[1,4,9,16,25,36,49,64], B = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"``\frac{x^2}{x^2+y^2}``", md"# Header", md"This is *very*, **very**, very, very, very, very, very, very, very long line" , - md""] + md"", + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" * + "∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"* + " * ∞7∫αγ\n"* + " * ∞8∫αγ\n"* + " * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* + " * γ∞1∫α\n"* + " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + ] ) - @test sprint(show, "text/plain", df) == - "5×2 DataFrame\n" * - "│ Row │ A │ B │\n" * - "│ │ Int64 │ Markdown.MD │\n" * - "├─────┼───────┼─────────────────────────────────────────────────────┤\n" * - "│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │\n" * - "│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │\n" * - "│ 3 │ 9 │ # Header │\n" * - "│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │\n" * - "│ 5 │ 25 │ │" - @test sprint(show, "text/csv", df) == - "\"A\",\"B\"\n"* - "1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\"\n"* - "4,\"\$\\\\frac{x^2}{x^2+y^2}\$\"\n"* - "9,\"# Header\"\n"* - "16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\"\n"* - "25,\"\"\n" + @test sprint(show, "text/plain", df) == """ +8×2 DataFrame +│ Row │ A │ B │ +│ │ Int64 │ Markdown.MD │ +├─────┼───────┼─────────────────────────────────────────────────────┤ +│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │ +│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ +│ 3 │ 9 │ # Header │ +│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │ +│ 5 │ 25 │ │ +│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │ +│ 7 │ 49 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ… │ +│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │""" + + @test sprint(show, "text/csv", df) == """ +\"A\",\"B\" +1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" +4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" +9,\"# Header\" +16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" +25,\"\" +36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +49,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\\n\\n * ∞7∫αγ\\n * ∞8∫αγ\\n * ∞9∫αγ∞0∫α\\n\\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +""" end @testset "Markdown as HTML" begin df = DataFrame( - A=Int64[1,4,9,16,25], - B = [ - md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", - md"``\frac{x^2}{x^2+y^2}``", - Markdown.parse("# Multi-line\nThis is a multi-line\n\n**Markdown**"), - md"This is *very*, **very**, very, very, very, very, very, very, very long line" , - md"" - ] + A=Int64[1,4,9,16,25,36,49,64], + B = [ + md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", + md"``\frac{x^2}{x^2+y^2}``", + md"# Header", + md"This is *very*, **very**, very, very, very, very, very, very, very long line" , + md"", + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" * + "∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"* + " * ∞7∫αγ\n"* + " * ∞8∫αγ\n"* + " * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* + " * γ∞1∫α\n"* + " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + ] ) @test sprint(show,"text/html",df) == - ""* - "" * - "" * - "

5 rows × 2 columns

" * - "" * - "" * - "" * - "" * - "
AB
Int64MD…
11" * - "" * - "
24" * - "

$\\frac{x^2}{x^2+y^2}$

\n
" * - "
39

Multi-line

\n" * - "

This is a multi-line

\n" * - "

Markdown

\n" * - "
416" * - "

This is very, very, very, very, very," * - " very, very, very, very long line

\n" * - "
525
" + "" * + "" * + "" * + "" * + "" * "

8 rows × 2 columns

" * + "" * + "" * + "" * + "" * + "" * + "" * + "" * + "
AB
Int64MD…
11
" * + "

DataFrames.jl

\n
24

$\\frac{x^2}{x^2+y^2}$

\n
39

Header

\n
416
" * + "

This is very, very, very, very, very, very, very, very, very long line

\n" * + "
525
636
" * + "

∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0

\n" * + "
749
" * + "

∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ

\n
    \n
  • ∞7∫αγ

    \n
  • \n
  • ∞8∫αγ

    \n
  • \n
  • ∞9∫αγ∞0∫α

    \n
  • \n
\n

γ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0

\n" * + "
864
" * + "

∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α

" * + "\n
    \n" * + "
  • γ∞1∫α

    \n
  • \n" * + "
  • γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0

    \n
  • \n" * + "
\n" * "
" end @testset "empty data frame and DataFrameRow" begin From 8a04964fc56ba35274c198078841aa519959cff1 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 6 Aug 2020 17:55:44 -0400 Subject: [PATCH 24/36] 32 it is... --- src/abstractdataframe/show.jl | 2 +- test/io.jl | 37 +++++++++++++++++------------------ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 6c3fbfccf6..af36f941c9 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -56,7 +56,7 @@ ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = ourshow(io, summary(x), styled=styled) function ourshow(io::IO, x::Markdown.MD) r = repr(x) - len = min(length(r, 1, something(findfirst(c->c=='\n', r), lastindex(r)+1)-1), 50) + len = min(length(r, 1, something(findfirst(==('\n'), r), lastindex(r)+1)-1), 32) return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) end diff --git a/test/io.jl b/test/io.jl index 5702b2b72c..7858ceaa8e 100644 --- a/test/io.jl +++ b/test/io.jl @@ -211,12 +211,11 @@ end md"# Header", md"This is *very*, **very**, very, very, very, very, very, very, very long line" , md"", - Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0" * - "∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), - Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\n"* - " * ∞7∫αγ\n"* - " * ∞8∫αγ\n"* - " * ∞9∫αγ∞0∫α\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3"), + Markdown.parse("∫αγ∞1∫αγ∞\n"* + " * 2∫αγ∞3∫αγ∞4\n"* + " * ∫αγ∞5∫αγ\n"* + " * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* " * γ∞1∫α\n"* " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), @@ -224,17 +223,17 @@ end ) @test sprint(show, "text/plain", df) == """ 8×2 DataFrame -│ Row │ A │ B │ -│ │ Int64 │ Markdown.MD │ -├─────┼───────┼─────────────────────────────────────────────────────┤ -│ 1 │ 1 │ [DataFrames.jl](http://juliadata.github.io/DataFra… │ -│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ -│ 3 │ 9 │ # Header │ -│ 4 │ 16 │ This is *very*, **very**, very, very, very, very, … │ -│ 5 │ 25 │ │ -│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │ -│ 7 │ 49 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ… │ -│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0… │""" +│ Row │ A │ B │ +│ │ Int64 │ Markdown.MD │ +├─────┼───────┼───────────────────────────────────┤ +│ 1 │ 1 │ [DataFrames.jl](http://juliadata… │ +│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ +│ 3 │ 9 │ # Header │ +│ 4 │ 16 │ This is *very*, **very**, very, … │ +│ 5 │ 25 │ │ +│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │ +│ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ +│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" @test sprint(show, "text/csv", df) == """ \"A\",\"B\" @@ -243,8 +242,8 @@ end 9,\"# Header\" 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" 25,\"\" -36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" -49,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ\\n\\n * ∞7∫αγ\\n * ∞8∫αγ\\n * ∞9∫αγ∞0∫α\\n\\nγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" +36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" +49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" """ end From 9fbe2644083851b6da6755f1f012e2910c3051fc Mon Sep 17 00:00:00 2001 From: Nicholas Ritchie Date: Fri, 7 Aug 2020 08:06:51 -0400 Subject: [PATCH 25/36] Use chomp to remove trailing '\n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bogumił Kamiński --- src/abstractdataframe/io.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index 5b4c17b69c..6218ed5608 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -424,7 +424,7 @@ function printtable(io::IO, if df[i,j] isa Markdown.MD print(io, quotemark) r=repr(df[i,j]) - escapedprint(io, first(r,max(0,length(r)-1)), quotestr) + escapedprint(io, chomp(r), quotestr) print(io, quotemark) elseif ! (etypes[j] <: Real) print(io, quotemark) From 43a047cfcdec8696ebeb373465d0af799f761602 Mon Sep 17 00:00:00 2001 From: nritchie Date: Mon, 24 Aug 2020 16:31:57 -0400 Subject: [PATCH 26/36] Fixing conflicts --- src/DataFrames.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DataFrames.jl b/src/DataFrames.jl index f278e702f8..13c918d5b9 100644 --- a/src/DataFrames.jl +++ b/src/DataFrames.jl @@ -7,6 +7,7 @@ using Base.Sort, Base.Order, Base.Iterators using TableTraits, IteratorInterfaceExtensions import LinearAlgebra: norm using Markdown +import LinearAlgebra: norm import DataAPI, DataAPI.All, From 8ff0ff0d905d547c25fb9dcefcdb9add95109939 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Tue, 25 Aug 2020 11:38:20 -0400 Subject: [PATCH 27/36] Pulling df[i,j] out and optimizing ourshow. --- src/abstractdataframe/io.jl | 13 +++++++------ src/abstractdataframe/show.jl | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index 6218ed5608..d5f294184e 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -416,22 +416,23 @@ function printtable(io::IO, quotestr = string(quotemark) for i in 1:n for j in 1:p - if ismissing(df[i, j]) + cell = df[i, j] + if ismissing(cell) print(io, missingstring) - elseif isnothing(df[i, j]) + elseif isnothing(cell) print(io, nothingstring) else - if df[i,j] isa Markdown.MD + if cell isa Markdown.MD print(io, quotemark) - r=repr(df[i,j]) + r = repr(cell) escapedprint(io, chomp(r), quotestr) print(io, quotemark) elseif ! (etypes[j] <: Real) print(io, quotemark) - escapedprint(io, df[i, j], quotestr) + escapedprint(io, cell, quotestr) print(io, quotemark) else - print(io, df[i, j]) + print(io, cell) end end if j < p diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index af36f941c9..4bbc203943 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -57,7 +57,7 @@ ourshow(io::IO, x::SHOW_TABULAR_TYPES; styled::Bool=false) = function ourshow(io::IO, x::Markdown.MD) r = repr(x) len = min(length(r, 1, something(findfirst(==('\n'), r), lastindex(r)+1)-1), 32) - return print(io, len < length(r) - 1 ? first(r, len)*"…" : first(r, len)) + return print(io, len < length(r) - 1 ? first(r, len)*'…' : first(r, len)) end # AbstractChar: https://github.com/JuliaLang/julia/pull/34730 (1.5.0-DEV.261) From e67308e7187503e536b48a965b6fcaf9df2cff78 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Tue, 25 Aug 2020 12:13:41 -0400 Subject: [PATCH 28/36] Formatting improvements --- test/io.jl | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/io.jl b/test/io.jl index 7858ceaa8e..7cfe0f39c3 100644 --- a/test/io.jl +++ b/test/io.jl @@ -4,7 +4,7 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown # Test LaTeX export @testset "LaTeX export" begin - df = DataFrame(A = 1:4, + df = DataFrame(A = convert.( Int64, 1:4), B = ["\$10.0", "M&F", "A~B", "\\alpha"], C = ["A", "B", "C", "S"], D = [1.0, 2.0, missing, 3.0], @@ -12,17 +12,16 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown F = Vector{String}(undef, 4), G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) - str = - "\\begin{tabular}{r|ccccccc}\n" * - "\t& A & B & C & D & E & F & G\\\\\n" * - "\t\\hline\n\t& "*repr(Int)*" & String & String & Float64? & Cat…? & String & MD…\\\\\n" * - "\t\\hline\n" * - "\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\\n" * - "\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\\n" * - "\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\\n" * - "\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\\n" * - "\\end{tabular}\n" - + str = """ + \\begin{tabular}{r|ccccccc} + \t& A & B & C & D & E & F & G\\\\ + \t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ + \t\\hline + \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ + \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ + \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ + \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ + \\end{tabular}\n""" @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str From ab4209caecfb1c6be91df5be15d39e1ab3b85de0 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Tue, 25 Aug 2020 12:16:08 -0400 Subject: [PATCH 29/36] Additional formatting improvements --- test/io.jl | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/io.jl b/test/io.jl index 7cfe0f39c3..1771ffe672 100644 --- a/test/io.jl +++ b/test/io.jl @@ -221,30 +221,30 @@ end ] ) @test sprint(show, "text/plain", df) == """ -8×2 DataFrame -│ Row │ A │ B │ -│ │ Int64 │ Markdown.MD │ -├─────┼───────┼───────────────────────────────────┤ -│ 1 │ 1 │ [DataFrames.jl](http://juliadata… │ -│ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ -│ 3 │ 9 │ # Header │ -│ 4 │ 16 │ This is *very*, **very**, very, … │ -│ 5 │ 25 │ │ -│ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │ -│ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ -│ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" + 8×2 DataFrame + │ Row │ A │ B │ + │ │ Int64 │ Markdown.MD │ + ├─────┼───────┼───────────────────────────────────┤ + │ 1 │ 1 │ [DataFrames.jl](http://juliadata… │ + │ 2 │ 4 │ \$\\frac{x^2}{x^2+y^2}\$ │ + │ 3 │ 9 │ # Header │ + │ 4 │ 16 │ This is *very*, **very**, very, … │ + │ 5 │ 25 │ │ + │ 6 │ 36 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │ + │ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ + │ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" @test sprint(show, "text/csv", df) == """ -\"A\",\"B\" -1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" -4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" -9,\"# Header\" -16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" -25,\"\" -36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" -49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" -64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" -""" + \"A\",\"B\" + 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" + 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" + 9,\"# Header\" + 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" + 25,\"\" + 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" + 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + """ end @testset "Markdown as HTML" begin From 4993be3f9fb72c953981efaab13d0848acc5ce7e Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 27 Aug 2020 12:07:24 -0400 Subject: [PATCH 30/36] Fixing triple-quoted strings in 1.0.X --- test/io.jl | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/test/io.jl b/test/io.jl index 1771ffe672..5149099f26 100644 --- a/test/io.jl +++ b/test/io.jl @@ -4,7 +4,7 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown # Test LaTeX export @testset "LaTeX export" begin - df = DataFrame(A = convert.( Int64, 1:4), + df = DataFrame(A = Int64.( 1:4 ), B = ["\$10.0", "M&F", "A~B", "\\alpha"], C = ["A", "B", "C", "S"], D = [1.0, 2.0, missing, 3.0], @@ -13,15 +13,16 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) str = """ - \\begin{tabular}{r|ccccccc} - \t& A & B & C & D & E & F & G\\\\ - \t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ - \t\\hline - \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ - \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ - \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ - \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ - \\end{tabular}\n""" +\\begin{tabular}{r|ccccccc} +\t& A & B & C & D & E & F & G\\\\ +\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ +\t\\hline +\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ +\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ +\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ +\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ +\\end{tabular} +""" @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str @@ -234,17 +235,18 @@ end │ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ │ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" - @test sprint(show, "text/csv", df) == """ - \"A\",\"B\" - 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" - 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" - 9,\"# Header\" - 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" - 25,\"\" - 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" - 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - """ + @test sprint(show, "text/csv", df) == + """ + \"A\",\"B\" + 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" + 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" + 9,\"# Header\" + 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" + 25,\"\" + 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" + 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + """ end @testset "Markdown as HTML" begin From feb0f5d0fa96557b8b00ddd80ffb185a91bf2bf3 Mon Sep 17 00:00:00 2001 From: Nicholas Ritchie Date: Thu, 27 Aug 2020 12:09:35 -0400 Subject: [PATCH 31/36] Strip space in test case Co-authored-by: Milan Bouchet-Valat --- test/io.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/io.jl b/test/io.jl index 5149099f26..aaeb903e9f 100644 --- a/test/io.jl +++ b/test/io.jl @@ -213,12 +213,12 @@ end md"", Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3"), Markdown.parse("∫αγ∞1∫αγ∞\n"* - " * 2∫αγ∞3∫αγ∞4\n"* - " * ∫αγ∞5∫αγ\n"* - " * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + " * 2∫αγ∞3∫αγ∞4\n"* + " * ∫αγ∞5∫αγ\n"* + " * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), Markdown.parse("∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\n"* - " * γ∞1∫α\n"* - " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), + " * γ∞1∫α\n"* + " * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0"), ] ) @test sprint(show, "text/plain", df) == """ From bbd5143c6417d6c4ffdbd36c0cb06fcde9892fda Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Thu, 27 Aug 2020 16:57:30 -0400 Subject: [PATCH 32/36] Using @nalimilan suggestion --- test/io.jl | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/test/io.jl b/test/io.jl index aaeb903e9f..b36d48c722 100644 --- a/test/io.jl +++ b/test/io.jl @@ -13,16 +13,25 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown G = [ md"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)", md"###A", md"``\frac{A}{B}``", md"*A*b**A**"] ) str = """ -\\begin{tabular}{r|ccccccc} -\t& A & B & C & D & E & F & G\\\\ -\t\\hline\n\t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ -\t\\hline -\t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl}\n\n \\\\ -\t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A\n\n \\\\ -\t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$\n\n \\\\ -\t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A}\n\n \\\\ -\\end{tabular} -""" + \\begin{tabular}{r|ccccccc} + \t& A & B & C & D & E & F & G\\\\ + \t\\hline + \t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ + \t\\hline + \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl} + + \\\\ + \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A + + \\\\ + \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$ + + \\\\ + \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A} + + \\\\ + \\end{tabular} + """ @test repr(MIME("text/latex"), df) == str @test repr(MIME("text/latex"), eachcol(df)) == str @@ -235,18 +244,18 @@ end │ 7 │ 49 │ ∫αγ∞1∫αγ∞… │ │ 8 │ 64 │ ∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫α… │""" - @test sprint(show, "text/csv", df) == - """ - \"A\",\"B\" - 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" - 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" - 9,\"# Header\" - 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" - 25,\"\" - 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" - 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" - """ + @test sprint(show, "text/csv", df) == + """ + \"A\",\"B\" + 1,\"[DataFrames.jl](http://juliadata.github.io/DataFrames.jl)\" + 4,\"\$\\\\frac{x^2}{x^2+y^2}\$\" + 9,\"# Header\" + 16,\"This is *very*, **very**, very, very, very, very, very, very, very long line\" + 25,\"\" + 36,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫αγ∞1∫αγ∞2∫αγ∞3\" + 49,\"∫αγ∞1∫αγ∞\\n\\n * 2∫αγ∞3∫αγ∞4\\n * ∫αγ∞5∫αγ\\n * ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + 64,\"∫αγ∞1∫αγ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0∫α\\n\\n * γ∞1∫α\\n * γ∞2∫αγ∞3∫αγ∞4∫αγ∞5∫αγ∞6∫αγ∞7∫αγ∞8∫αγ∞9∫αγ∞0\" + """ end @testset "Markdown as HTML" begin From 088c89486cf228511a5afaa39da7f7440acaac35 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Fri, 28 Aug 2020 08:30:38 -0400 Subject: [PATCH 33/36] Improving LaTeX output appearance, NEWS.md entry --- NEWS.md | 2 ++ src/abstractdataframe/io.jl | 2 +- test/io.jl | 16 ++++------------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index 135e857113..c8a65badd1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,6 +42,8 @@ ([#2373](https://github.com/JuliaData/DataFrames.jl/pull/2373)) * add `columnindex` for `DataFrameRow` ([#2380](https://github.com/JuliaData/DataFrames.jl/pull/2380)) +* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX + ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) ## Deprecated diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index d5f294184e..eda9a60200 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -307,7 +307,7 @@ function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; if ismissing(cell) print(io, "\\emph{missing}") elseif cell isa Markdown.MD - show(io, "text/latex", cell) + print(io, strip(repr(MIME("text/latex"), cell))) elseif cell isa SHOW_TABULAR_TYPES print(io, "\\emph{") print(io, latex_escape(sprint(ourshow, cell, context=io))) diff --git a/test/io.jl b/test/io.jl index b36d48c722..83065b6a90 100644 --- a/test/io.jl +++ b/test/io.jl @@ -18,18 +18,10 @@ using Test, DataFrames, CategoricalArrays, Dates, Markdown \t\\hline \t& Int64 & String & String & Float64? & Cat…? & String & MD…\\\\ \t\\hline - \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl} - - \\\\ - \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A - - \\\\ - \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$ - - \\\\ - \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A} - - \\\\ + \t1 & 1 & \\\$10.0 & A & 1.0 & a & \\emph{\\#undef} & \\href{http://juliadata.github.io/DataFrames.jl}{DataFrames.jl} \\\\ + \t2 & 2 & M\\&F & B & 2.0 & \\emph{missing} & \\emph{\\#undef} & \\#\\#\\#A \\\\ + \t3 & 3 & A\\textasciitilde{}B & C & \\emph{missing} & c & \\emph{\\#undef} & \$\\frac{A}{B}\$ \\\\ + \t4 & 4 & \\textbackslash{}\\textbackslash{}alpha & S & 3.0 & d & \\emph{\\#undef} & \\emph{A}b\\textbf{A} \\\\ \\end{tabular} """ From 6a2ed0d33dfe97a4267e461e3a31c59e5c9a492a Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Fri, 28 Aug 2020 08:34:10 -0400 Subject: [PATCH 34/36] Moved NEWS.md item to "Other relevant changes" section. --- NEWS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index c8a65badd1..dd303bf6eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,8 +42,6 @@ ([#2373](https://github.com/JuliaData/DataFrames.jl/pull/2373)) * add `columnindex` for `DataFrameRow` ([#2380](https://github.com/JuliaData/DataFrames.jl/pull/2380)) -* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX - ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) ## Deprecated @@ -57,3 +55,5 @@ * Documentation is now available also in *Dark* mode ([#2315](https://github.com/JuliaData/DataFrames.jl/pull/2315)) +* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX + ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) From b3866e51c4e6597bf147f3c54b131e1d0584f699 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Fri, 28 Aug 2020 08:52:59 -0400 Subject: [PATCH 35/36] Correct NEWS.md item on rich display support --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index dd303bf6eb..f96081a08f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -55,5 +55,5 @@ * Documentation is now available also in *Dark* mode ([#2315](https://github.com/JuliaData/DataFrames.jl/pull/2315)) -* add rich display support for Markdown cell entries in HTML, Markdown and LaTeX +* add rich display support for Markdown cell entries in HTML and LaTeX ([#2346](https://github.com/JuliaData/DataFrames.jl/pull/2346)) From 1342b4bb6b0d04bb5f62121faf0f203bce9a9992 Mon Sep 17 00:00:00 2001 From: "Nicholas W. M. Ritchie" Date: Fri, 28 Aug 2020 09:19:34 -0400 Subject: [PATCH 36/36] Removing duplicate using lines --- src/DataFrames.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/DataFrames.jl b/src/DataFrames.jl index 5767987173..b2724b94f0 100644 --- a/src/DataFrames.jl +++ b/src/DataFrames.jl @@ -7,8 +7,6 @@ using Base.Sort, Base.Order, Base.Iterators using TableTraits, IteratorInterfaceExtensions using Markdown import LinearAlgebra: norm -using Markdown -import LinearAlgebra: norm import DataAPI, DataAPI.All,