forked from JuliaData/DataFrames.jl
/
show.jl
74 lines (61 loc) · 2.71 KB
/
show.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function Base.show(io::IO, gd::GroupedDataFrame;
allgroups::Bool = !get(io, :limit, false),
allrows::Bool = !get(io, :limit, false),
allcols::Bool = !get(io, :limit, false),
splitcols::Bool = get(io, :limit, false),
rowlabel::Symbol = :Row,
summary::Bool = true)
N = length(gd)
grouped_names = names(gd.parent)[gd.cols]
keys = join(':' .* string.(grouped_names), ", ")
keystr = length(gd.cols) > 1 ? "keys" : "key"
groupstr = N > 1 ? "groups" : "group"
summary && print(io, "$(typeof(gd)) with $N $groupstr based on $keystr: $keys")
if allgroups
for i = 1:N
nrows = size(gd[i], 1)
rows = nrows > 1 ? "rows" : "row"
grouped_values = [first(gd[i][col]) for col in gd.cols]
print(io, "\nFirst Group: $nrows $rows")
for (name, value) in zip(grouped_names, grouped_values)
print(io, "\n:$(name) => $value")
end
show(io, gd[i], summary=false,
allrows=allrows, allcols=allcols, rowlabel=rowlabel)
end
else
if N > 0
nrows = size(gd[1], 1)
rows = nrows > 1 ? "rows" : "row"
grouped_values = [first(gd[1][col]) for col in gd.cols]
print(io, "\nFirst Group: $nrows $rows")
for (name, value) in zip(grouped_names, grouped_values)
print(io, "\n:$(name) => $value")
end
show(io, gd[1], summary=false,
allrows=allrows, allcols=allcols, rowlabel=rowlabel)
end
if N > 1
nrows = size(gd[N], 1)
rows = nrows > 1 ? "rows" : "row"
grouped_values = [first(gd[N][col]) for col in gd.cols]
print(io, "\nFirst Group: $nrows $rows")
for (name, value) in zip(grouped_names, grouped_values)
print(io, "\n:$(name) => $value")
end
show(io, gd[N], summary=false,
allrows=allrows, allcols=allcols, rowlabel=rowlabel)
end
end
end
function Base.show(df::GroupedDataFrame;
allrows::Bool = !get(stdout, :limit, true),
allcols::Bool = !get(stdout, :limit, true),
allgroups::Bool = !get(stdout, :limit, true),
splitcols::Bool = get(stdout, :limit, true),
rowlabel::Symbol = :Row,
summary::Bool = true) # -> Nothing
return show(stdout, df,
allrows=allrows, allcols=allcols, allgroups=allgroups, splitcols=splitcols,
rowlabel=rowlabel, summary=summary)
end