Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion docs/src/man/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ You can adjust how data frame is displayed by calling the `show` function manual
`show(german, allcols=true)` does the same for columns, e.g.:

```jldoctest dataframe
julia> show(german, allcols=true)
julia> show(MIME("text/plain"), german, allcols=true)
1000×10 DataFrame
Row │ id Age Sex Job Housing Saving accounts Checking account Credit amount Duration Purpose
│ Int64 Int64 String7 Int64 String7 String15 String15 Int64 Int64 String31
Expand Down
9 changes: 5 additions & 4 deletions docs/src/man/customizing_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ julia> df

julia> # Using this option, no cell will be truncated if there is room to display it.

julia> show(df; truncate = 0)
julia> show(MIME("text/plain"), df; truncate = 0)
3×3 DataFrame
Row │ a b c
│ Int64 Float64 String
Expand All @@ -64,7 +64,7 @@ julia> show(df; truncate = 0)

julia> # Hide row numbers.

julia> show(df; show_row_number = false)
julia> show(MIME("text/plain"), df; show_row_number = false)
3×3 DataFrame
a b c
Int64 Float64 String
Expand All @@ -75,7 +75,7 @@ julia> show(df; show_row_number = false)

julia> # Hide the column element types in text output.

julia> show(df; eltypes = false)
julia> show(MIME("text/plain"), df; eltypes = false)
3×3 DataFrame
Row │ a b c
─────┼─────────────────────────────────────────────
Expand Down Expand Up @@ -140,7 +140,7 @@ julia> function parentheses_fmt(v, i, j)
return v
end;

julia> show(df; formatters = [parentheses_fmt])
julia> show(MIME("text/plain"), df; formatters = [parentheses_fmt])
7×5 DataFrame
Row │ A B C D E
│ Float64 Float64 Float64 Float64 Float64
Expand Down Expand Up @@ -190,6 +190,7 @@ julia> profit = DataFrame(
);

julia> show(
MIME("text/plain"),
profit;
# We use this option to align the summary rows with the data rows at the decimal
# point.
Expand Down
68 changes: 2 additions & 66 deletions docs/src/man/split_apply_combine.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,71 +635,7 @@ data frame and get a vector of results either use a comprehension or `collect`
`GroupedDataFrame` into a vector first. Here are examples of both approaches:

```jldoctest sac
julia> sdf_vec = collect(iris_gdf)
3-element Vector{Any}:
50×5 SubDataFrame
Row │ SepalLength SepalWidth PetalLength PetalWidth Species
│ Float64 Float64 Float64 Float64 String15
─────┼───────────────────────────────────────────────────────────────
1 │ 5.1 3.5 1.4 0.2 Iris-setosa
2 │ 4.9 3.0 1.4 0.2 Iris-setosa
3 │ 4.7 3.2 1.3 0.2 Iris-setosa
4 │ 4.6 3.1 1.5 0.2 Iris-setosa
5 │ 5.0 3.6 1.4 0.2 Iris-setosa
6 │ 5.4 3.9 1.7 0.4 Iris-setosa
7 │ 4.6 3.4 1.4 0.3 Iris-setosa
8 │ 5.0 3.4 1.5 0.2 Iris-setosa
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮
44 │ 5.0 3.5 1.6 0.6 Iris-setosa
45 │ 5.1 3.8 1.9 0.4 Iris-setosa
46 │ 4.8 3.0 1.4 0.3 Iris-setosa
47 │ 5.1 3.8 1.6 0.2 Iris-setosa
48 │ 4.6 3.2 1.4 0.2 Iris-setosa
49 │ 5.3 3.7 1.5 0.2 Iris-setosa
50 │ 5.0 3.3 1.4 0.2 Iris-setosa
35 rows omitted
50×5 SubDataFrame
Row │ SepalLength SepalWidth PetalLength PetalWidth Species
│ Float64 Float64 Float64 Float64 String15
─────┼───────────────────────────────────────────────────────────────────
1 │ 7.0 3.2 4.7 1.4 Iris-versicolor
2 │ 6.4 3.2 4.5 1.5 Iris-versicolor
3 │ 6.9 3.1 4.9 1.5 Iris-versicolor
4 │ 5.5 2.3 4.0 1.3 Iris-versicolor
5 │ 6.5 2.8 4.6 1.5 Iris-versicolor
6 │ 5.7 2.8 4.5 1.3 Iris-versicolor
7 │ 6.3 3.3 4.7 1.6 Iris-versicolor
8 │ 4.9 2.4 3.3 1.0 Iris-versicolor
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮
44 │ 5.0 2.3 3.3 1.0 Iris-versicolor
45 │ 5.6 2.7 4.2 1.3 Iris-versicolor
46 │ 5.7 3.0 4.2 1.2 Iris-versicolor
47 │ 5.7 2.9 4.2 1.3 Iris-versicolor
48 │ 6.2 2.9 4.3 1.3 Iris-versicolor
49 │ 5.1 2.5 3.0 1.1 Iris-versicolor
50 │ 5.7 2.8 4.1 1.3 Iris-versicolor
35 rows omitted
50×5 SubDataFrame
Row │ SepalLength SepalWidth PetalLength PetalWidth Species
│ Float64 Float64 Float64 Float64 String15
─────┼──────────────────────────────────────────────────────────────────
1 │ 6.3 3.3 6.0 2.5 Iris-virginica
2 │ 5.8 2.7 5.1 1.9 Iris-virginica
3 │ 7.1 3.0 5.9 2.1 Iris-virginica
4 │ 6.3 2.9 5.6 1.8 Iris-virginica
5 │ 6.5 3.0 5.8 2.2 Iris-virginica
6 │ 7.6 3.0 6.6 2.1 Iris-virginica
7 │ 4.9 2.5 4.5 1.7 Iris-virginica
8 │ 7.3 2.9 6.3 1.8 Iris-virginica
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮
44 │ 6.8 3.2 5.9 2.3 Iris-virginica
45 │ 6.7 3.3 5.7 2.5 Iris-virginica
46 │ 6.7 3.0 5.2 2.3 Iris-virginica
47 │ 6.3 2.5 5.0 1.9 Iris-virginica
48 │ 6.5 3.0 5.2 2.0 Iris-virginica
49 │ 6.2 3.4 5.4 2.3 Iris-virginica
50 │ 5.9 3.0 5.1 1.8 Iris-virginica
35 rows omitted
julia> sdf_vec = collect(iris_gdf);

julia> map(nrow, sdf_vec)
3-element Vector{Int64}:
Expand Down Expand Up @@ -942,7 +878,7 @@ julia> df = DataFrame(customer_id=["a", "b", "b", "b", "c", "c"],

julia> gdf = groupby(df, :customer_id, sort=true);

julia> show(gdf, allgroups=true)
julia> show(MIME("text/plain"), gdf, allgroups=true)
GroupedDataFrame with 3 groups based on key: customer_id
Group 1 (1 row): customer_id = "a"
Row │ customer_id transaction_id volume
Expand Down
20 changes: 3 additions & 17 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2947,23 +2947,9 @@ as a `SubDataFrame`.
```jldoctest
julia> collect(Iterators.partition(DataFrame(x=1:5), 2))
3-element Vector{SubDataFrame{DataFrame, DataFrames.Index, UnitRange{Int64}}}:
2×1 SubDataFrame
Row │ x
│ Int64
─────┼───────
1 │ 1
2 │ 2
2×1 SubDataFrame
Row │ x
│ Int64
─────┼───────
1 │ 3
2 │ 4
1×1 SubDataFrame
Row │ x
│ Int64
─────┼───────
1 │ 5
SubDataFrame{DataFrame, DataFrames.Index, UnitRange{Int64}}(DataFrame(AbstractVector[[1, 2, 3, 4, 5]], DataFrames.Index(Dict(:x => 1), [:x]), nothing, nothing, true), DataFrames.Index(Dict(:x => 1), [:x]), 1:2)
SubDataFrame{DataFrame, DataFrames.Index, UnitRange{Int64}}(DataFrame(AbstractVector[[1, 2, 3, 4, 5]], DataFrames.Index(Dict(:x => 1), [:x]), nothing, nothing, true), DataFrames.Index(Dict(:x => 1), [:x]), 3:4)
SubDataFrame{DataFrame, DataFrames.Index, UnitRange{Int64}}(DataFrame(AbstractVector[[1, 2, 3, 4, 5]], DataFrames.Index(Dict(:x => 1), [:x]), nothing, nothing, true), DataFrames.Index(Dict(:x => 1), [:x]), 5:5)
```
"""
function Iterators.partition(df::AbstractDataFrame, n::Integer)
Expand Down
2 changes: 0 additions & 2 deletions src/abstractdataframe/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ 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) =
printtable(io, df, header = true, separator = '\t')
Base.show(io::IO, mime::MIME"text/plain", df::AbstractDataFrame; kwargs...) =
show(io, df; kwargs...)

##############################################################################
#
Expand Down
12 changes: 8 additions & 4 deletions src/abstractdataframe/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ else
end

"""
show([io::IO, ]df::AbstractDataFrame;
show([io::IO, ],
::MIME"text/plain",
df::AbstractDataFrame;
allrows::Bool = !get(io, :limit, false),
allcols::Bool = !get(io, :limit, false),
allgroups::Bool = !get(io, :limit, false),
Expand Down Expand Up @@ -453,7 +455,7 @@ julia> using DataFrames

julia> df = DataFrame(A=1:3, B=["x", "y", "z"]);

julia> show(df, row_labels=nothing)
julia> show(MIME("text/plain"), df, row_labels=nothing)
3×2 DataFrame
A B
Int64 String
Expand All @@ -464,6 +466,7 @@ julia> show(df, row_labels=nothing)
```
"""
function Base.show(io::IO,
::MIME"text/plain",
df::AbstractDataFrame;
allrows::Bool = !get(io, :limit, false),
allcols::Bool = !get(io, :limit, false),
Expand All @@ -480,15 +483,16 @@ function Base.show(io::IO,
summary=summary, eltypes=eltypes, truncate=truncate, kwargs...)
end

Base.show(df::AbstractDataFrame;
Base.show(::MIME"text/plain",
df::AbstractDataFrame;
allrows::Bool = !get(stdout, :limit, true),
allcols::Bool = !get(stdout, :limit, true),
rowlabel::Symbol = :Row,
summary::Bool = true,
eltypes::Bool = true,
truncate::Int = 32,
kwargs...) =
show(stdout, df;
show(stdout, MIME("text/plain"), df;
allrows=allrows, allcols=allcols, rowlabel=rowlabel, summary=summary,
eltypes=eltypes, truncate=truncate, kwargs...)

Expand Down
3 changes: 2 additions & 1 deletion src/groupeddataframe/groupeddataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ julia> gd[k]
2 │ 1 2 5

julia> for g in gd
println(g)
show(MIME("text/plain"), g)
println()
end
2×3 SubDataFrame
Row │ a b c
Expand Down
13 changes: 7 additions & 6 deletions src/groupeddataframe/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Base.summary(io::IO, gd::GroupedDataFrame)
join(io, groupcols(gd), ", ")
end

function Base.show(io::IO, gd::GroupedDataFrame;
function Base.show(io::IO, ::MIME"text/plain", gd::GroupedDataFrame;
allgroups::Bool = !get(io, :limit, false),
allrows::Bool = !get(io, :limit, false),
allcols::Bool = !get(io, :limit, false),
Expand All @@ -33,7 +33,7 @@ function Base.show(io::IO, gd::GroupedDataFrame;
join(io, identified_groups, ", ")
println(io)

show(io, gd[i]; summary=false,
show(io, MIME("text/plain"), gd[i]; summary=false,
allrows=allrows, allcols=allcols, rowlabel=rowlabel,
truncate=truncate, kwargs...)
end
Expand Down Expand Up @@ -90,7 +90,7 @@ function Base.show(io::IO, gd::GroupedDataFrame;
join(io, identified_groups, ", ")
println(io)

show(io, gd[1]; summary=false,
show(io, MIME("text/plain"), gd[1]; summary=false,
allrows=allrows, allcols=allcols, rowlabel=rowlabel,
truncate=truncate, display_size=(h1, w), kwargs...)

Expand All @@ -106,21 +106,22 @@ function Base.show(io::IO, gd::GroupedDataFrame;
join(io, identified_groups, ", ")
println(io)

show(io, gd[N]; summary=false,
show(io, MIME("text/plain"), gd[N]; summary=false,
allrows=allrows, allcols=allcols, rowlabel=rowlabel,
truncate=truncate, display_size=(h2, w), kwargs...)
end
end

function Base.show(df::GroupedDataFrame;
function Base.show(::MIME"text/plain",
df::GroupedDataFrame;
allrows::Bool = !get(stdout, :limit, true),
allcols::Bool = !get(stdout, :limit, true),
allgroups::Bool = !get(stdout, :limit, true),
rowlabel::Symbol = :Row,
summary::Bool = true,
truncate::Int = 32,
kwargs...) # -> Nothing
return show(stdout, df;
return show(stdout, MIME("text/plain"), df;
allrows=allrows, allcols=allcols, allgroups=allgroups,
rowlabel=rowlabel, summary=summary, truncate=truncate,
kwargs...)
Expand Down
16 changes: 8 additions & 8 deletions test/grouping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ end
C=Float32[1.0, 2.0, 3.0, 4.0])
gd = groupby_checked(df, :A)
io = IOContext(IOBuffer(), :limit=>true)
show(io, gd)
show(io, MIME("text/plain"), gd)
str = String(take!(io.io))
summary_str = summary(gd)
@test summary_str == "GroupedDataFrame with 4 groups based on key: A"
Expand All @@ -1451,7 +1451,7 @@ end
│ Int64 String Float32
─────┼────────────────────────
1 │ 4 A\\nC 4.0"""
show(io, gd, allgroups=true)
show(io, MIME("text/plain"), gd, allgroups=true)
str = String(take!(io.io))
@test str == """
$summary_str
Expand All @@ -1476,17 +1476,17 @@ end
─────┼────────────────────────
1 │ 4 A\\nC 4.0"""

# Test two-argument show
# Test three-argument show
str1, dsize = capture_stdout() do
show(gd)
show(MIME("text/plain"), gd)
end
io = IOContext(IOBuffer(), :limit=>true, :displaysize=>dsize)
show(io, gd)
show(io, MIME("text/plain"), gd)
str2 = String(take!(io.io))
@test str1 == str2

# Test error when invalid keyword arguments are passed in text backend.
@test_throws ArgumentError show(stdout, gd, max_column_width="100px")
@test_throws ArgumentError show(stdout, MIME("text/plain"), gd, max_column_width="100px")

str = sprint(show, "text/html", gd)
@test str == "<p>" *
Expand Down Expand Up @@ -1591,7 +1591,7 @@ end
gd = groupby_checked(DataFrame(a=[Symbol("&")], b=["&"]), [1, 2])
summary_str = summary(gd)
@test summary_str == "GroupedDataFrame with 1 group based on keys: a, b"
@test sprint(show, gd) === """
@test sprint(show, MIME("text/plain"), gd) === """
$summary_str
Group 1 (1 row): a = :&, b = "&"
Row │ a b
Expand Down Expand Up @@ -1782,7 +1782,7 @@ end
@test isequal_typed(DataFrame(gdf), df)

# work around automatic trimming of trailing whitespace in most editors
@test sprint(show, groupby_checked(df, [])) ==
@test sprint(show, MIME("text/plain"), groupby_checked(df, [])) ==
"GroupedDataFrame with 1 group based on key: \n" *
"Group 1 (3 rows): \n" *
""" Row │ x1 x2 y
Expand Down
20 changes: 5 additions & 15 deletions test/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ end
nothing]

io = IOBuffer()
show(io, df)
show(io, MIME("text/plain"), df)
str = String(take!(io))

@test str == """
Expand All @@ -1488,7 +1488,7 @@ end
# TODO: update when https://github.com/KristofferC/Crayons.jl/issues/47 is resolved
if Base.get_have_color()
io = IOBuffer()
show(IOContext(io, :color => true), df)
show(IOContext(io, :color => true), MIME("text/plain"), df)
str = String(take!(io))
@test str == """
\e[1m9×2 DataFrame\e[0m
Expand Down Expand Up @@ -1755,19 +1755,9 @@ end
─────┼───────────────────────────────────
1 │ 01234567890123456789012345678901…"""

io = IOBuffer()
show(io, df)
str = String(take!(io))
@test str == """
1×1 DataFrame
Row │ x
│ String
─────┼───────────────────────────────────
1 │ 01234567890123456789012345678901…"""

# no truncation
io = IOBuffer()
show(io, df, truncate=0)
show(io, MIME("text/plain"), df, truncate=0)
str = String(take!(io))
@test str == """
1×1 DataFrame
Expand All @@ -1778,7 +1768,7 @@ end

# custom truncation
io = IOBuffer()
show(io, df, truncate=1)
show(io, MIME("text/plain"), df, truncate=1)
str = String(take!(io))
@test str == """
1×1 DataFrame
Expand All @@ -1790,7 +1780,7 @@ end

df = DataFrame(x12345678901234567890="0123456789"^10)
io = IOBuffer()
show(io, df, truncate=1, rowlabel=:r12345678901234567890)
show(io, MIME("text/plain"), df, truncate=1, rowlabel=:r12345678901234567890)
str = String(take!(io))
@test str == """
1×1 DataFrame
Expand Down
Loading
Loading