Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add displaycoltypes to showrows & show for dataframes #2142

Merged
merged 18 commits into from
Mar 12, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions src/abstractdataframe/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
under the column name in the heading. Defaults to true.
under the column name in the heading. Defaults to `true`.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 052de9a

- `rowid = nothing`: Used to handle showing `DataFrameRow`

# Examples
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -569,6 +576,7 @@ function _show(io::IO,
allcols,
rowlabel,
summary,
coltypes,
rowid)
return
end
Expand Down Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 052de9a


# Examples
```jldoctest
Expand All @@ -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)