From 22fa7659f3a270b2443c3f0cc51a11dc2d0406e0 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Thu, 5 Mar 2020 13:27:25 -0500 Subject: [PATCH 01/16] add displaycoltypes to showrows show for dataframes --- src/abstractdataframe/show.jl | 47 +++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index ecd71aa4d7..a978f628c7 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -363,6 +363,7 @@ end allcols::Bool = false, rowlabel::Symbol = :Row, displaysummary::Bool = true, + displaycoltypes::Bool = true, rowid=nothing) Render a subset of rows (possibly in chunks) of an `AbstractDataFrame` to an @@ -390,6 +391,8 @@ NOTE: The value of `maxwidths[end]` must be the string width of - `displaysummary::Bool`: Should a brief string summary of the AbstractDataFrame be rendered to the I/O stream before printing the contents of the renderable rows? Defaults to `true`. +- `displaycoltype::Bool = true`: Whether to print the column type + under the column name in the heading. Defaults to true. - `rowid = nothing`: Used to handle showing `DataFrameRow` # Examples @@ -417,6 +420,7 @@ function showrows(io::IO, allcols::Bool = false, rowlabel::Symbol = :Row, displaysummary::Bool = true, + displaycoltypes::Bool = true, rowid=nothing) # -> Void ncols = size(df, 2) @@ -463,23 +467,25 @@ function showrows(io::IO, end # Print column types - print(io, "│ ") - padding = rowmaxwidth - for itr in 1:padding - write(io, ' ') - end - print(io, " │ ") - for j in leftcol:rightcol - s = compacttype(eltype(df[!, j]), maxwidths[j]) - printstyled(io, s, color=:light_black) - padding = maxwidths[j] - ourstrwidth(io, s) + if displaycoltypes + print(io, "│ ") + padding = rowmaxwidth for itr in 1:padding write(io, ' ') end - if j == rightcol - print(io, " │\n") - else - print(io, " │ ") + print(io, " │ ") + for j in leftcol:rightcol + s = compacttype(eltype(df[!, j]), maxwidths[j]) + printstyled(io, s, color=:light_black) + padding = maxwidths[j] - ourstrwidth(io, s) + for itr in 1:padding + write(io, ' ') + end + if j == rightcol + print(io, " │\n") + else + print(io, " │ ") + end end end @@ -537,6 +543,7 @@ function _show(io::IO, splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, summary::Bool = true, + coltypes::Bool = true, rowid=nothing) _check_consistency(df) nrows = size(df, 1) @@ -569,6 +576,7 @@ function _show(io::IO, allcols, rowlabel, summary, + coltypes, rowid) return end @@ -607,6 +615,7 @@ while `splitcols` defaults to `true`. By default this is the case only if `io` has the `IOContext` property `limit` set. - `rowlabel::Symbol = :Row`: The label to use for the column containing row numbers. - `summary::Bool = true`: Whether to print a brief string summary of the data frame. +- `coltypes::Bool = true`: Whether to print the column types under column names in data frame. # Examples ```jldoctest @@ -630,16 +639,18 @@ Base.show(io::IO, allcols::Bool = !get(io, :limit, false), splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, - summary::Bool = true) = + summary::Bool = true, + coltypes::Bool = true ) = _show(io, df, allrows=allrows, allcols=allcols, splitcols=splitcols, - rowlabel=rowlabel, summary=summary) + rowlabel=rowlabel, summary=summary, coltypes=coltypes) Base.show(df::AbstractDataFrame; allrows::Bool = !get(stdout, :limit, true), allcols::Bool = !get(stdout, :limit, true), splitcols = get(stdout, :limit, true), rowlabel::Symbol = :Row, - summary::Bool = true) = + summary::Bool = true, + coltypes::Bool = true) = show(stdout, df, allrows=allrows, allcols=allcols, splitcols=splitcols, - rowlabel=rowlabel, summary=summary) + rowlabel=rowlabel, summary=summary, coltypes=coltypes) From d0df307dd37ea82b7e88fbdc3d230d611a9c2f14 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Fri, 6 Mar 2020 08:12:20 -0500 Subject: [PATCH 02/16] fix column width (eltypes calc) for displaycolumn bool --- src/abstractdataframe/show.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index a978f628c7..b5882f6d44 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -122,7 +122,8 @@ function getmaxwidths(df::AbstractDataFrame, rowindices1::AbstractVector{Int}, rowindices2::AbstractVector{Int}, rowlabel::Symbol, - rowid=nothing) # -> Vector{Int} + rowid=nothing, + show_eltype = true) # -> Vector{Int} maxwidths = Vector{Int}(undef, size(df, 2) + 1) undefstrwidth = ourstrwidth(io, Base.undef_ref_str) @@ -131,7 +132,6 @@ function getmaxwidths(df::AbstractDataFrame, for (name, col) in pairs(eachcol(df)) # (1) Consider length of column name maxwidth = ourstrwidth(io, name) - # (2) Consider length of longest entry in that column for indices in (rowindices1, rowindices2), i in indices if isassigned(col, i) @@ -140,7 +140,11 @@ function getmaxwidths(df::AbstractDataFrame, maxwidth = max(maxwidth, undefstrwidth) end end - maxwidths[j] = max(maxwidth, ourstrwidth(io, compacttype(eltype(col)))) + if show_eltype + maxwidths[j] = max(maxwidth, ourstrwidth(io, compacttype(eltype(col)))) + else + maxwidths[j] = maxwidth + end j += 1 end @@ -565,7 +569,7 @@ function _show(io::IO, rowindices1 = 1:bound rowindices2 = max(bound + 1, nrows - nrowssubset + 1):nrows end - maxwidths = getmaxwidths(df, io, rowindices1, rowindices2, rowlabel, rowid) + maxwidths = getmaxwidths(df, io, rowindices1, rowindices2, rowlabel, rowid, coltypes) width = getprintedwidth(maxwidths) showrows(io, df, @@ -640,7 +644,7 @@ Base.show(io::IO, splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, summary::Bool = true, - coltypes::Bool = true ) = + coltypes::Bool = true) = _show(io, df, allrows=allrows, allcols=allcols, splitcols=splitcols, rowlabel=rowlabel, summary=summary, coltypes=coltypes) From 052de9a4ab78773f691ddbf4acbdacef0fdd3abe Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Sun, 8 Mar 2020 10:51:43 -0400 Subject: [PATCH 03/16] update show.jl w/ code review comments --- src/abstractdataframe/show.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index b5882f6d44..9bc71a1f92 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -132,6 +132,7 @@ function getmaxwidths(df::AbstractDataFrame, for (name, col) in pairs(eachcol(df)) # (1) Consider length of column name maxwidth = ourstrwidth(io, name) + # (2) Consider length of longest entry in that column for indices in (rowindices1, rowindices2), i in indices if isassigned(col, i) @@ -396,7 +397,7 @@ NOTE: The value of `maxwidths[end]` must be the string width of AbstractDataFrame be rendered to the I/O stream before printing the contents of the renderable rows? Defaults to `true`. - `displaycoltype::Bool = true`: Whether to print the column type - under the column name in the heading. Defaults to true. + under the column name in the heading. Defaults to `true`. - `rowid = nothing`: Used to handle showing `DataFrameRow` # Examples @@ -619,7 +620,7 @@ while `splitcols` defaults to `true`. By default this is the case only if `io` has the `IOContext` property `limit` set. - `rowlabel::Symbol = :Row`: The label to use for the column containing row numbers. - `summary::Bool = true`: Whether to print a brief string summary of the data frame. -- `coltypes::Bool = true`: Whether to print the column types under column names in data frame. +- `coltypes::Bool = true`: Whether to print the column types under column names. # Examples ```jldoctest From 4890c3a789ebcc748fc858f90ac74545bf871e65 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Thu, 5 Mar 2020 13:27:25 -0500 Subject: [PATCH 04/16] add displaycoltypes to showrows show for dataframes --- src/abstractdataframe/show.jl | 58 ++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index ecd71aa4d7..9bc71a1f92 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -122,7 +122,8 @@ function getmaxwidths(df::AbstractDataFrame, rowindices1::AbstractVector{Int}, rowindices2::AbstractVector{Int}, rowlabel::Symbol, - rowid=nothing) # -> Vector{Int} + rowid=nothing, + show_eltype = true) # -> Vector{Int} maxwidths = Vector{Int}(undef, size(df, 2) + 1) undefstrwidth = ourstrwidth(io, Base.undef_ref_str) @@ -140,7 +141,11 @@ function getmaxwidths(df::AbstractDataFrame, maxwidth = max(maxwidth, undefstrwidth) end end - maxwidths[j] = max(maxwidth, ourstrwidth(io, compacttype(eltype(col)))) + if show_eltype + maxwidths[j] = max(maxwidth, ourstrwidth(io, compacttype(eltype(col)))) + else + maxwidths[j] = maxwidth + end j += 1 end @@ -363,6 +368,7 @@ end allcols::Bool = false, rowlabel::Symbol = :Row, displaysummary::Bool = true, + displaycoltypes::Bool = true, rowid=nothing) Render a subset of rows (possibly in chunks) of an `AbstractDataFrame` to an @@ -390,6 +396,8 @@ NOTE: The value of `maxwidths[end]` must be the string width of - `displaysummary::Bool`: Should a brief string summary of the AbstractDataFrame be rendered to the I/O stream before printing the contents of the renderable rows? Defaults to `true`. +- `displaycoltype::Bool = true`: Whether to print the column type + under the column name in the heading. Defaults to `true`. - `rowid = nothing`: Used to handle showing `DataFrameRow` # Examples @@ -417,6 +425,7 @@ function showrows(io::IO, allcols::Bool = false, rowlabel::Symbol = :Row, displaysummary::Bool = true, + displaycoltypes::Bool = true, rowid=nothing) # -> Void ncols = size(df, 2) @@ -463,23 +472,25 @@ function showrows(io::IO, end # Print column types - print(io, "│ ") - padding = rowmaxwidth - for itr in 1:padding - write(io, ' ') - end - print(io, " │ ") - for j in leftcol:rightcol - s = compacttype(eltype(df[!, j]), maxwidths[j]) - printstyled(io, s, color=:light_black) - padding = maxwidths[j] - ourstrwidth(io, s) + if displaycoltypes + print(io, "│ ") + padding = rowmaxwidth for itr in 1:padding write(io, ' ') end - if j == rightcol - print(io, " │\n") - else - print(io, " │ ") + print(io, " │ ") + for j in leftcol:rightcol + s = compacttype(eltype(df[!, j]), maxwidths[j]) + printstyled(io, s, color=:light_black) + padding = maxwidths[j] - ourstrwidth(io, s) + for itr in 1:padding + write(io, ' ') + end + if j == rightcol + print(io, " │\n") + else + print(io, " │ ") + end end end @@ -537,6 +548,7 @@ function _show(io::IO, splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, summary::Bool = true, + coltypes::Bool = true, rowid=nothing) _check_consistency(df) nrows = size(df, 1) @@ -558,7 +570,7 @@ function _show(io::IO, rowindices1 = 1:bound rowindices2 = max(bound + 1, nrows - nrowssubset + 1):nrows end - maxwidths = getmaxwidths(df, io, rowindices1, rowindices2, rowlabel, rowid) + maxwidths = getmaxwidths(df, io, rowindices1, rowindices2, rowlabel, rowid, coltypes) width = getprintedwidth(maxwidths) showrows(io, df, @@ -569,6 +581,7 @@ function _show(io::IO, allcols, rowlabel, summary, + coltypes, rowid) return end @@ -607,6 +620,7 @@ while `splitcols` defaults to `true`. By default this is the case only if `io` has the `IOContext` property `limit` set. - `rowlabel::Symbol = :Row`: The label to use for the column containing row numbers. - `summary::Bool = true`: Whether to print a brief string summary of the data frame. +- `coltypes::Bool = true`: Whether to print the column types under column names. # Examples ```jldoctest @@ -630,16 +644,18 @@ Base.show(io::IO, allcols::Bool = !get(io, :limit, false), splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, - summary::Bool = true) = + summary::Bool = true, + coltypes::Bool = true) = _show(io, df, allrows=allrows, allcols=allcols, splitcols=splitcols, - rowlabel=rowlabel, summary=summary) + rowlabel=rowlabel, summary=summary, coltypes=coltypes) Base.show(df::AbstractDataFrame; allrows::Bool = !get(stdout, :limit, true), allcols::Bool = !get(stdout, :limit, true), splitcols = get(stdout, :limit, true), rowlabel::Symbol = :Row, - summary::Bool = true) = + summary::Bool = true, + coltypes::Bool = true) = show(stdout, df, allrows=allrows, allcols=allcols, splitcols=splitcols, - rowlabel=rowlabel, summary=summary) + rowlabel=rowlabel, summary=summary, coltypes=coltypes) From afec4cad6c53fc10eac56f642b715c64b944c840 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Mon, 9 Mar 2020 16:53:15 -0400 Subject: [PATCH 05/16] add coltypes to text/html show --- src/abstractdataframe/io.jl | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index d0376472ff..5030088c18 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -37,8 +37,8 @@ julia> show(stdout, MIME("text/csv"), DataFrame(A = 1:3, B = ["x", "y", "z"])) ``` """ Base.show(io::IO, mime::MIME, df::AbstractDataFrame) -Base.show(io::IO, mime::MIME"text/html", df::AbstractDataFrame; summary::Bool=true) = - _show(io, mime, df, summary=summary) +Base.show(io::IO, mime::MIME"text/html", df::AbstractDataFrame; summary::Bool=true, coltypes::Bool=true) = + _show(io, mime, df, summary=summary, coltypes=coltypes) Base.show(io::IO, mime::MIME"text/latex", df::AbstractDataFrame) = _show(io, mime, df) Base.show(io::IO, mime::MIME"text/csv", df::AbstractDataFrame) = @@ -77,7 +77,7 @@ function html_escape(cell::AbstractString) end function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; - summary::Bool=true, rowid::Union{Int,Nothing}=nothing) + summary::Bool=true, rowid::Union{Int,Nothing}=nothing, coltypes::Bool=true) _check_consistency(df) if rowid !== nothing if size(df, 2) == 0 @@ -104,13 +104,15 @@ function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; write(io, "$(html_escape(String(column_name)))") end write(io, "") - write(io, "") - write(io, "") - for j in 1:mxcol - s = html_escape(compacttype(eltype(df[!, j]))) - write(io, "$s") + if coltypes + write(io, "") + write(io, "") + for j in 1:mxcol + s = html_escape(compacttype(eltype(df[!, j]))) + write(io, "$s") + end + write(io, "") end - write(io, "") write(io, "") write(io, "") if summary @@ -150,25 +152,25 @@ function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; write(io, "") end -function Base.show(io::IO, mime::MIME"text/html", dfr::DataFrameRow; summary::Bool=true) +function Base.show(io::IO, mime::MIME"text/html", dfr::DataFrameRow; summary::Bool=true, coltypes::Bool=true) r, c = parentindices(dfr) summary && write(io, "

DataFrameRow ($(length(dfr)) columns)

") - _show(io, mime, view(parent(dfr), [r], c), summary=false, rowid=r) + _show(io, mime, view(parent(dfr), [r], c), summary=false, rowid=r, coltypes=coltypes) end -function Base.show(io::IO, mime::MIME"text/html", dfrs::DataFrameRows; summary::Bool=true) +function Base.show(io::IO, mime::MIME"text/html", dfrs::DataFrameRows; summary::Bool=true, coltypes::Bool=true) df = parent(dfrs) summary && write(io, "

$(nrow(df))×$(ncol(df)) DataFrameRows

") - _show(io, mime, df, summary=false) + _show(io, mime, df, summary=false, coltypes=coltypes) end function Base.show(io::IO, mime::MIME"text/html", dfcs::DataFrameColumns; - summary::Bool=true) + summary::Bool=true, coltypes::Bool=true) df = parent(dfcs) if summary write(io, "

$(nrow(df))×$(ncol(df)) DataFrameColumns

") end - _show(io, mime, df, summary=false) + _show(io, mime, df, summary=false, coltypes=coltypes) end function Base.show(io::IO, mime::MIME"text/html", gd::GroupedDataFrame) From 41b335ba313c8f87539772a0de8d7a78baa87184 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 08:37:44 -0400 Subject: [PATCH 06/16] change coltypes/displaycoltypes => eltypes --- src/abstractdataframe/io.jl | 20 ++++++++++---------- src/abstractdataframe/show.jl | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index 5030088c18..a5503a0eec 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -37,8 +37,8 @@ julia> show(stdout, MIME("text/csv"), DataFrame(A = 1:3, B = ["x", "y", "z"])) ``` """ Base.show(io::IO, mime::MIME, df::AbstractDataFrame) -Base.show(io::IO, mime::MIME"text/html", df::AbstractDataFrame; summary::Bool=true, coltypes::Bool=true) = - _show(io, mime, df, summary=summary, coltypes=coltypes) +Base.show(io::IO, mime::MIME"text/html", df::AbstractDataFrame; summary::Bool=true, eltypes::Bool=true) = + _show(io, mime, df, summary=summary, eltypes=eltypes) Base.show(io::IO, mime::MIME"text/latex", df::AbstractDataFrame) = _show(io, mime, df) Base.show(io::IO, mime::MIME"text/csv", df::AbstractDataFrame) = @@ -77,7 +77,7 @@ function html_escape(cell::AbstractString) end function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; - summary::Bool=true, rowid::Union{Int,Nothing}=nothing, coltypes::Bool=true) + summary::Bool=true, rowid::Union{Int,Nothing}=nothing, eltypes::Bool=true) _check_consistency(df) if rowid !== nothing if size(df, 2) == 0 @@ -104,7 +104,7 @@ function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; write(io, "$(html_escape(String(column_name)))") end write(io, "") - if coltypes + if eltypes write(io, "") write(io, "") for j in 1:mxcol @@ -152,25 +152,25 @@ function _show(io::IO, ::MIME"text/html", df::AbstractDataFrame; write(io, "") end -function Base.show(io::IO, mime::MIME"text/html", dfr::DataFrameRow; summary::Bool=true, coltypes::Bool=true) +function Base.show(io::IO, mime::MIME"text/html", dfr::DataFrameRow; summary::Bool=true, eltypes::Bool=true) r, c = parentindices(dfr) summary && write(io, "

DataFrameRow ($(length(dfr)) columns)

") - _show(io, mime, view(parent(dfr), [r], c), summary=false, rowid=r, coltypes=coltypes) + _show(io, mime, view(parent(dfr), [r], c), summary=false, rowid=r, eltypes=eltypes) end -function Base.show(io::IO, mime::MIME"text/html", dfrs::DataFrameRows; summary::Bool=true, coltypes::Bool=true) +function Base.show(io::IO, mime::MIME"text/html", dfrs::DataFrameRows; summary::Bool=true, eltypes::Bool=true) df = parent(dfrs) summary && write(io, "

$(nrow(df))×$(ncol(df)) DataFrameRows

") - _show(io, mime, df, summary=false, coltypes=coltypes) + _show(io, mime, df, summary=false, eltypes=eltypes) end function Base.show(io::IO, mime::MIME"text/html", dfcs::DataFrameColumns; - summary::Bool=true, coltypes::Bool=true) + summary::Bool=true, eltypes::Bool=true) df = parent(dfcs) if summary write(io, "

$(nrow(df))×$(ncol(df)) DataFrameColumns

") end - _show(io, mime, df, summary=false, coltypes=coltypes) + _show(io, mime, df, summary=false, eltypes=eltypes) end function Base.show(io::IO, mime::MIME"text/html", gd::GroupedDataFrame) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 3301857cc7..1585e7ce35 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -400,7 +400,7 @@ end allcols::Bool = false, rowlabel::Symbol = :Row, displaysummary::Bool = true, - displaycoltypes::Bool = true, + eltypes::Bool = true, rowid=nothing) Render a subset of rows (possibly in chunks) of an `AbstractDataFrame` to an @@ -428,7 +428,7 @@ NOTE: The value of `maxwidths[end]` must be the string width of - `displaysummary::Bool`: Should a brief string summary of the AbstractDataFrame be rendered to the I/O stream before printing the contents of the renderable rows? Defaults to `true`. -- `displaycoltype::Bool = true`: Whether to print the column type +- `eltypes::Bool = true`: Whether to print the column type under the column name in the heading. Defaults to `true`. - `rowid = nothing`: Used to handle showing `DataFrameRow` @@ -457,7 +457,7 @@ function showrows(io::IO, allcols::Bool = false, rowlabel::Symbol = :Row, displaysummary::Bool = true, - displaycoltypes::Bool = true, + eltypes::Bool = true, rowid=nothing) # -> Void ncols = size(df, 2) @@ -504,7 +504,7 @@ function showrows(io::IO, end # Print column types - if displaycoltypes + if eltypes print(io, "│ ") padding = rowmaxwidth for itr in 1:padding @@ -580,7 +580,7 @@ function _show(io::IO, splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, summary::Bool = true, - coltypes::Bool = true, + eltypes::Bool = true, rowid=nothing) _check_consistency(df) nrows = size(df, 1) @@ -602,7 +602,7 @@ function _show(io::IO, rowindices1 = 1:bound rowindices2 = max(bound + 1, nrows - nrowssubset + 1):nrows end - maxwidths = getmaxwidths(df, io, rowindices1, rowindices2, rowlabel, rowid, coltypes) + maxwidths = getmaxwidths(df, io, rowindices1, rowindices2, rowlabel, rowid, eltypes) width = getprintedwidth(maxwidths) showrows(io, df, @@ -613,7 +613,7 @@ function _show(io::IO, allcols, rowlabel, summary, - coltypes, + eltypes, rowid) return end @@ -652,7 +652,7 @@ while `splitcols` defaults to `true`. By default this is the case only if `io` has the `IOContext` property `limit` set. - `rowlabel::Symbol = :Row`: The label to use for the column containing row numbers. - `summary::Bool = true`: Whether to print a brief string summary of the data frame. -- `coltypes::Bool = true`: Whether to print the column types under column names. +- `eltypes::Bool = true`: Whether to print the column types under column names. # Examples ```jldoctest @@ -677,9 +677,9 @@ Base.show(io::IO, splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, summary::Bool = true, - coltypes::Bool = true) = + eltypes::Bool = true) = _show(io, df, allrows=allrows, allcols=allcols, splitcols=splitcols, - rowlabel=rowlabel, summary=summary, coltypes=coltypes) + rowlabel=rowlabel, summary=summary, eltypes=eltypes) Base.show(df::AbstractDataFrame; allrows::Bool = !get(stdout, :limit, true), @@ -687,7 +687,7 @@ Base.show(df::AbstractDataFrame; splitcols = get(stdout, :limit, true), rowlabel::Symbol = :Row, summary::Bool = true, - coltypes::Bool = true) = + eltypes::Bool = true) = show(stdout, df, allrows=allrows, allcols=allcols, splitcols=splitcols, - rowlabel=rowlabel, summary=summary, coltypes=coltypes) + rowlabel=rowlabel, summary=summary, eltypes=eltypes) From cd4219f990164caf35448bb787879c250e82d59d Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 08:50:01 -0400 Subject: [PATCH 07/16] add eltypes to text/latex --- src/abstractdataframe/io.jl | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index a5503a0eec..ee53227674 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -39,8 +39,8 @@ julia> show(stdout, MIME("text/csv"), DataFrame(A = 1:3, B = ["x", "y", "z"])) Base.show(io::IO, mime::MIME, df::AbstractDataFrame) Base.show(io::IO, mime::MIME"text/html", df::AbstractDataFrame; summary::Bool=true, eltypes::Bool=true) = _show(io, mime, df, summary=summary, eltypes=eltypes) -Base.show(io::IO, mime::MIME"text/latex", df::AbstractDataFrame) = - _show(io, mime, df) +Base.show(io::IO, mime::MIME"text/latex", df::AbstractDataFrame; eltypes::Bool=true) = + _show(io, mime, df, eltypes=eltypes) Base.show(io::IO, mime::MIME"text/csv", df::AbstractDataFrame) = printtable(io, df, header = true, separator = ',') Base.show(io::IO, mime::MIME"text/tab-separated-values", df::AbstractDataFrame) = @@ -228,7 +228,7 @@ function latex_escape(cell::AbstractString) replace(cell, ['\\','~','#','$','%','&','_','^','{','}']=>latex_char_escape) end -function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; rowid=nothing) +function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; rowid=nothing, eltypes=true) _check_consistency(df) if rowid !== nothing if size(df, 2) == 0 @@ -258,12 +258,14 @@ function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; rowid=nothing) mxcol < size(df, 2) && write(io, " & ") write(io, "\\\\\n") write(io, "\t\\hline\n") - write(io, "\t& ") - header = join(map(c -> latex_escape(string(compacttype(c))), eltype.(eachcol(df)[1:mxcol])), " & ") - write(io, header) - mxcol < size(df, 2) && write(io, " & ") - write(io, "\\\\\n") - write(io, "\t\\hline\n") + if eltypes + write(io, "\t& ") + header = join(map(c -> latex_escape(string(compacttype(c))), eltype.(eachcol(df)[1:mxcol])), " & ") + write(io, header) + mxcol < size(df, 2) && write(io, " & ") + write(io, "\\\\\n") + write(io, "\t\\hline\n") + end for row in 1:mxrow write(io, "\t") write(io, @sprintf("%d", rowid === nothing ? row : rowid)) @@ -292,13 +294,13 @@ function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; rowid=nothing) write(io, "\\end{tabular}\n") end -function Base.show(io::IO, mime::MIME"text/latex", dfr::DataFrameRow) +function Base.show(io::IO, mime::MIME"text/latex", dfr::DataFrameRow; eltypes::Bool=true) r, c = parentindices(dfr) - _show(io, mime, view(parent(dfr), [r], c), rowid=r) + _show(io, mime, view(parent(dfr), [r], c), rowid=r, eltypes=eltypes) end -Base.show(io::IO, mime::MIME"text/latex", dfrs::DataFrameRows) = _show(io, mime, parent(dfrs)) -Base.show(io::IO, mime::MIME"text/latex", dfcs::DataFrameColumns) = _show(io, mime, parent(dfcs)) +Base.show(io::IO, mime::MIME"text/latex", dfrs::DataFrameRows; eltypes::Bool=true) = _show(io, mime, parent(dfrs), eltypes=eltypes) +Base.show(io::IO, mime::MIME"text/latex", dfcs::DataFrameColumns; eltypes::Bool=true) = _show(io, mime, parent(dfcs), eltypes=eltypes) function Base.show(io::IO, mime::MIME"text/latex", gd::GroupedDataFrame) N = length(gd) From b31502b64e0a1d1a11b52752f82fed560c6b1d2e Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 08:54:36 -0400 Subject: [PATCH 08/16] add eltypes to text/plain --- src/abstractdataframe/io.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index ee53227674..c63374a218 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -50,9 +50,10 @@ Base.show(io::IO, mime::MIME"text/plain", df::AbstractDataFrame; allcols::Bool = !get(io, :limit, false), splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, - summary::Bool = true) = + summary::Bool = true, + eltypes::Bool = true) = show(io, df, allrows=allrows, allcols=allcols, - splitcols=splitcols, rowlabel=rowlabel, summary=summary) + splitcols=splitcols, rowlabel=rowlabel, summary=summary, eltypes=eltypes) ############################################################################## # From ebaf0b5d9d5bcea5e222ed80cca7a11f12701cc5 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 09:27:41 -0400 Subject: [PATCH 09/16] add tests for show plain latex html --- src/abstractdataframe/io.jl | 2 +- test/io.jl | 44 +++++++++++++++++++++++++++++++++++++ test/show.jl | 27 +++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index c63374a218..caca65085b 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -50,7 +50,7 @@ Base.show(io::IO, mime::MIME"text/plain", df::AbstractDataFrame; allcols::Bool = !get(io, :limit, false), splitcols = get(io, :limit, false), rowlabel::Symbol = :Row, - summary::Bool = true, + summary::Bool = true, eltypes::Bool = true) = show(io, df, allrows=allrows, allcols=allcols, splitcols=splitcols, rowlabel=rowlabel, summary=summary, eltypes=eltypes) diff --git a/test/io.jl b/test/io.jl index d2822483e9..bdf2b07409 100644 --- a/test/io.jl +++ b/test/io.jl @@ -242,4 +242,48 @@ end end end +@testset "eltypes tests" + df = DataFrame(A = 1:3, B = ["x", "y", "z"]) + + io = IOBuffer() + show(io, MIME("text/plain"), df, eltypes=true) + str = String(take!(io)) + @test str == "3×2 DataFrame\n│ Row │ A │ B │\n│ │ Int64 │ String │\n├─────┼───────┼────────┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │" + + io = IOBuffer() + show(io, MIME("text/plain"), df, eltypes=false) + str = String(take!(io)) + @test str == "3×2 DataFrame\n│ Row │ A │ B │\n├─────┼───┼───┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │" + + io = IOBuffer() + show(io, MIME("text/html"), df, eltypes=true) + str = String(take!(io)) + @test str == "" * + "" * + "

3 rows × 2 columns

" * + "" * + "
" * + "AB
Int64String
11x
22y
33z
" + + io = IOBuffer() + show(io, MIME("text/html"), df, eltypes=false) + str = String(take!(io)) + @test str == "" * + "

3 rows × 2 columns

" * + "" * + "
" * + "AB
11x
22y
33z
" + + io = IOBuffer() + show(io, MIME("text/latex"), df, eltypes=true) + str = String(take!(io)) + @test str == "\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t& Int64 & String\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n" + + io = IOBuffer() + show(io, MIME("text/latex"), df, eltypes=false) + str = String(take!(io)) + @test str == "\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n" + +end + end # module diff --git a/test/show.jl b/test/show.jl index 61cbf67265..376956a8eb 100644 --- a/test/show.jl +++ b/test/show.jl @@ -460,4 +460,31 @@ end │ 1 │ missing │""" end +@testset "wide type name" begin + df = DataFrame(A = 1:3, B = ["x", "y", "z"]) + + io = IOBuffer() + show(io, df, eltypes=true) + str = String(take!(io)) + @test str == """ + 3×2 DataFrame + │ Row │ A │ B │ + │ │ Int64 │ String │ + ├─────┼───────┼────────┤ + │ 1 │ 1 │ x │ + │ 2 │ 2 │ y │ + │ 3 │ 3 │ z │""" + + io = IOBuffer() + show(io, df, eltypes=false) + str = String(take!(io)) + @test str == """ + 3×2 DataFrame + │ Row │ A │ B │ + ├─────┼───┼───┤ + │ 1 │ 1 │ x │ + │ 2 │ 2 │ y │ + │ 3 │ 3 │ z │""" +end + end # module From 4ac1217abc90980fdebcea84b4c28a3a32ae18fb Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 11:43:24 -0400 Subject: [PATCH 10/16] fix testset block --- test/io.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/io.jl b/test/io.jl index bdf2b07409..170caeeb37 100644 --- a/test/io.jl +++ b/test/io.jl @@ -242,7 +242,7 @@ end end end -@testset "eltypes tests" +@testset "eltypes tests" begin df = DataFrame(A = 1:3, B = ["x", "y", "z"]) io = IOBuffer() From 5c904e40b08b6e900a0884b5ce88aa328b49a9ff Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 14:51:26 -0400 Subject: [PATCH 11/16] cast dataframe test column to Int32 to work both on x86 and 64 bit tests --- test/io.jl | 7 ++++--- test/show.jl | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/io.jl b/test/io.jl index 170caeeb37..1e44f60a8f 100644 --- a/test/io.jl +++ b/test/io.jl @@ -244,11 +244,12 @@ end @testset "eltypes tests" begin df = DataFrame(A = 1:3, B = ["x", "y", "z"]) + df.A = map(x -> Int32(x), df[:A]) io = IOBuffer() show(io, MIME("text/plain"), df, eltypes=true) str = String(take!(io)) - @test str == "3×2 DataFrame\n│ Row │ A │ B │\n│ │ Int64 │ String │\n├─────┼───────┼────────┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │" + @test str == "3×2 DataFrame\n│ Row │ A │ B │\n│ │ Int32 │ String │\n├─────┼───────┼────────┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │" io = IOBuffer() show(io, MIME("text/plain"), df, eltypes=false) @@ -260,7 +261,7 @@ end str = String(take!(io)) @test str == "" * - "" * + "" * "

3 rows × 2 columns

" * "" * "
" * "AB
Int64String
Int32String
11x
22y
33z
" @@ -277,7 +278,7 @@ end io = IOBuffer() show(io, MIME("text/latex"), df, eltypes=true) str = String(take!(io)) - @test str == "\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t& Int64 & String\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n" + @test str == "\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t& Int32 & String\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n" io = IOBuffer() show(io, MIME("text/latex"), df, eltypes=false) diff --git a/test/show.jl b/test/show.jl index 376956a8eb..a9de868915 100644 --- a/test/show.jl +++ b/test/show.jl @@ -462,6 +462,7 @@ end @testset "wide type name" begin df = DataFrame(A = 1:3, B = ["x", "y", "z"]) + df.A = map(x -> Int32(x), df[:A]) io = IOBuffer() show(io, df, eltypes=true) @@ -469,7 +470,7 @@ end @test str == """ 3×2 DataFrame │ Row │ A │ B │ - │ │ Int64 │ String │ + │ │ Int32 │ String │ ├─────┼───────┼────────┤ │ 1 │ 1 │ x │ │ 2 │ 2 │ y │ From 3a7b031d5cde40d60f0c910b24a360cd66c0b0d4 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 16:27:42 -0400 Subject: [PATCH 12/16] fix show_eltype formatting --- src/abstractdataframe/show.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 1585e7ce35..034affbad1 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -155,7 +155,7 @@ function getmaxwidths(df::AbstractDataFrame, rowindices2::AbstractVector{Int}, rowlabel::Symbol, rowid=nothing, - show_eltype = true) # -> Vector{Int} + show_eltype=true) # -> Vector{Int} maxwidths = Vector{Int}(undef, size(df, 2) + 1) undefstrwidth = ourstrwidth(io, Base.undef_ref_str) From 4bb652999ec58bd4b93c81b1d762adb00eea9499 Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 16:29:20 -0400 Subject: [PATCH 13/16] wrap tests strings in triple quotes instead of single quotes --- test/io.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/io.jl b/test/io.jl index 1e44f60a8f..ef33776d8c 100644 --- a/test/io.jl +++ b/test/io.jl @@ -249,12 +249,12 @@ end io = IOBuffer() show(io, MIME("text/plain"), df, eltypes=true) str = String(take!(io)) - @test str == "3×2 DataFrame\n│ Row │ A │ B │\n│ │ Int32 │ String │\n├─────┼───────┼────────┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │" + @test str == """3×2 DataFrame\n│ Row │ A │ B │\n│ │ Int32 │ String │\n├─────┼───────┼────────┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │""" io = IOBuffer() show(io, MIME("text/plain"), df, eltypes=false) str = String(take!(io)) - @test str == "3×2 DataFrame\n│ Row │ A │ B │\n├─────┼───┼───┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │" + @test str == """3×2 DataFrame\n│ Row │ A │ B │\n├─────┼───┼───┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │""" io = IOBuffer() show(io, MIME("text/html"), df, eltypes=true) @@ -278,12 +278,12 @@ end io = IOBuffer() show(io, MIME("text/latex"), df, eltypes=true) str = String(take!(io)) - @test str == "\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t& Int32 & String\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n" + @test str == """\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t& Int32 & String\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n""" io = IOBuffer() show(io, MIME("text/latex"), df, eltypes=false) str = String(take!(io)) - @test str == "\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n" + @test str == """\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n""" end From de7e4e9d604e10742abf1af04ec913a5438a3d5b Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Tue, 10 Mar 2020 16:33:21 -0400 Subject: [PATCH 14/16] split functions onto multiple lines --- src/abstractdataframe/io.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index caca65085b..eb957d8a60 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -300,8 +300,10 @@ function Base.show(io::IO, mime::MIME"text/latex", dfr::DataFrameRow; eltypes::B _show(io, mime, view(parent(dfr), [r], c), rowid=r, eltypes=eltypes) end -Base.show(io::IO, mime::MIME"text/latex", dfrs::DataFrameRows; eltypes::Bool=true) = _show(io, mime, parent(dfrs), eltypes=eltypes) -Base.show(io::IO, mime::MIME"text/latex", dfcs::DataFrameColumns; eltypes::Bool=true) = _show(io, mime, parent(dfcs), eltypes=eltypes) +Base.show(io::IO, mime::MIME"text/latex", dfrs::DataFrameRows; eltypes::Bool=true) = + _show(io, mime, parent(dfrs), eltypes=eltypes) +Base.show(io::IO, mime::MIME"text/latex", dfcs::DataFrameColumns; eltypes::Bool=true) = + _show(io, mime, parent(dfcs), eltypes=eltypes) function Base.show(io::IO, mime::MIME"text/latex", gd::GroupedDataFrame) N = length(gd) From a9d733f4b8ca15d918f2b8909e8bd86eb3c4f20d Mon Sep 17 00:00:00 2001 From: Shan Sikdar Date: Wed, 11 Mar 2020 12:01:39 -0400 Subject: [PATCH 15/16] improve the visual formatting of the strings in io tests --- test/io.jl | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/test/io.jl b/test/io.jl index ef33776d8c..47dc56fd87 100644 --- a/test/io.jl +++ b/test/io.jl @@ -249,12 +249,25 @@ end io = IOBuffer() show(io, MIME("text/plain"), df, eltypes=true) str = String(take!(io)) - @test str == """3×2 DataFrame\n│ Row │ A │ B │\n│ │ Int32 │ String │\n├─────┼───────┼────────┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │""" + @test str == """ + 3×2 DataFrame + │ Row │ A │ B │ + │ │ Int32 │ String │ + ├─────┼───────┼────────┤ + │ 1 │ 1 │ x │ + │ 2 │ 2 │ y │ + │ 3 │ 3 │ z │""" io = IOBuffer() show(io, MIME("text/plain"), df, eltypes=false) str = String(take!(io)) - @test str == """3×2 DataFrame\n│ Row │ A │ B │\n├─────┼───┼───┤\n│ 1 │ 1 │ x │\n│ 2 │ 2 │ y │\n│ 3 │ 3 │ z │""" + @test str == """ + 3×2 DataFrame + │ Row │ A │ B │ + ├─────┼───┼───┤ + │ 1 │ 1 │ x │ + │ 2 │ 2 │ y │ + │ 3 │ 3 │ z │""" io = IOBuffer() show(io, MIME("text/html"), df, eltypes=true) @@ -278,13 +291,30 @@ end io = IOBuffer() show(io, MIME("text/latex"), df, eltypes=true) str = String(take!(io)) - @test str == """\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t& Int32 & String\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n""" + @test str == """ + \\begin{tabular}{r|cc} + \t& A & B\\\\ + \t\\hline + \t& Int32 & String\\\\ + \t\\hline + \t1 & 1 & x \\\\ + \t2 & 2 & y \\\\ + \t3 & 3 & z \\\\ + \\end{tabular} + """ io = IOBuffer() show(io, MIME("text/latex"), df, eltypes=false) str = String(take!(io)) - @test str == """\\begin{tabular}{r|cc}\n\t& A & B\\\\\n\t\\hline\n\t1 & 1 & x \\\\\n\t2 & 2 & y \\\\\n\t3 & 3 & z \\\\\n\\end{tabular}\n""" - + @test str == """ + \\begin{tabular}{r|cc} + \t& A & B\\\\ + \t\\hline + \t1 & 1 & x \\\\ + \t2 & 2 & y \\\\ + \t3 & 3 & z \\\\ + \\end{tabular} + """ end end # module From aaf4376422bada34f945981b2915ce7dfa4820d7 Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Thu, 12 Mar 2020 10:26:27 +0100 Subject: [PATCH 16/16] Apply suggestions from code review --- src/abstractdataframe/io.jl | 3 ++- src/abstractdataframe/show.jl | 2 +- test/io.jl | 3 +-- test/show.jl | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/abstractdataframe/io.jl b/src/abstractdataframe/io.jl index eb957d8a60..eb67105530 100644 --- a/src/abstractdataframe/io.jl +++ b/src/abstractdataframe/io.jl @@ -229,7 +229,8 @@ function latex_escape(cell::AbstractString) replace(cell, ['\\','~','#','$','%','&','_','^','{','}']=>latex_char_escape) end -function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; rowid=nothing, eltypes=true) +function _show(io::IO, ::MIME"text/latex", df::AbstractDataFrame; + rowid=nothing, eltypes::Bool=true) _check_consistency(df) if rowid !== nothing if size(df, 2) == 0 diff --git a/src/abstractdataframe/show.jl b/src/abstractdataframe/show.jl index 034affbad1..0be29e69ae 100644 --- a/src/abstractdataframe/show.jl +++ b/src/abstractdataframe/show.jl @@ -155,7 +155,7 @@ function getmaxwidths(df::AbstractDataFrame, rowindices2::AbstractVector{Int}, rowlabel::Symbol, rowid=nothing, - show_eltype=true) # -> Vector{Int} + show_eltype::Bool=true) # -> Vector{Int} maxwidths = Vector{Int}(undef, size(df, 2) + 1) undefstrwidth = ourstrwidth(io, Base.undef_ref_str) diff --git a/test/io.jl b/test/io.jl index 47dc56fd87..0f35fcf633 100644 --- a/test/io.jl +++ b/test/io.jl @@ -243,8 +243,7 @@ end end @testset "eltypes tests" begin - df = DataFrame(A = 1:3, B = ["x", "y", "z"]) - df.A = map(x -> Int32(x), df[:A]) + df = DataFrame(A = Int32.(1:3), B = ["x", "y", "z"]) io = IOBuffer() show(io, MIME("text/plain"), df, eltypes=true) diff --git a/test/show.jl b/test/show.jl index a9de868915..8f68fa47d0 100644 --- a/test/show.jl +++ b/test/show.jl @@ -461,8 +461,7 @@ end end @testset "wide type name" begin - df = DataFrame(A = 1:3, B = ["x", "y", "z"]) - df.A = map(x -> Int32(x), df[:A]) + df = DataFrame(A = Int32.(1:3), B = ["x", "y", "z"]) io = IOBuffer() show(io, df, eltypes=true)