Skip to content

Commit 01bf52f

Browse files
authored
Improve the speed of displaying large datasets in Jupyter Notebook (#81)
fix #82 * Improve the speed of displaying large datasets in Jupyter Notebook Fix the issue that Jupyter Notebook takes too much time when displaying large datasets with many columns. The getmaxwidths() function now only calculates the maximum width of the columns that will be displayed, not all columns. Please see issue for more details. * Modify the initialization code of maxwidths Now might break the loop before filling all the values of maxwidths. The initialize code of maxwidths has been modified.
1 parent 289f907 commit 01bf52f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/abstractdataset/io.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ function getmaxwidths(ds::AbstractDataset,
4545
show_eltype::Bool,
4646
buffer::IOBuffer,
4747
truncstring::Int)
48-
maxwidths = Vector{Int}(undef, size(ds, 2) + 1)
48+
maxwidths = zeros(Int, size(ds, 2) + 1)
4949

5050
undefstrwidth = ourstrwidth(io, "#undef", buffer, truncstring)
5151

5252
ct = show_eltype ? batch_compacttype(Any[eltype(c) for c in eachcol(ds)]) : String[]
53+
tty_cols = displaysize(io)[2]
54+
maxwidthsum = 0
5355
j = 1
5456
for (col_idx, (name, col)) in enumerate(pairs(eachcol(ds)))
5557
# (1) Consider length of column name
@@ -70,7 +72,12 @@ function getmaxwidths(ds::AbstractDataset,
7072
else
7173
maxwidths[j] = maxwidth
7274
end
75+
maxwidthsum += (maxwidths[j] + 2)
7376
j += 1
77+
# If the sum of column widths is already larger than COLUMNS, do not need calculate max width for the rest columns
78+
if maxwidthsum >= tty_cols
79+
break
80+
end
7481
end
7582

7683
# do not truncate rowlabel

0 commit comments

Comments
 (0)