Skip to content

Commit

Permalink
Merge e4eece1 into fc30dd8
Browse files Browse the repository at this point in the history
  • Loading branch information
zsunberg committed Jun 11, 2019
2 parents fc30dd8 + e4eece1 commit a96db23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/distributions/pretty_printing.jl
Expand Up @@ -15,7 +15,7 @@ function showdistribution(io::IO, mime::MIME"text/plain", d; title=string(typeof
rows = first(get(io, :displaysize, displaysize(io)))
rows -= 6 # Yuck! This magic number is also in Base.print_matrix

if limited && rows > 1
if limited && rows > 1 && length(support(d)) >= rows
for (x,p) in Iterators.take(weighted_iterator(d), rows-1)
push!(strings, sprint(show, x)) # maybe this should have conext=:compact=>true
push!(probs, p)
Expand Down
7 changes: 7 additions & 0 deletions test/test_pretty_printing.jl
Expand Up @@ -6,3 +6,10 @@ iob = IOBuffer()
io = IOContext(iob, :limit=>true, :displaysize=>(10, 7))
showdistribution(io, d)
@test String(take!(iob)) == " SparseCat{UnitRange{Int64},Array{Float64,1}} distribution\n ┌ ┐ \n 1 ┤■ 0.02 \n 2 ┤■ 0.02 \n 3 ┤■ 0.02 \n <everything else> ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.94 \n └ ┘ "

# test that it doesn't print <everything else> when there are enough lines
d = SparseCat([:a], 1.0)
iob = IOBuffer()
io = IOContext(iob, :limit=>true, :displaysize=>(10, 7))
showdistribution(io, d)
@test String(take!(iob)) == " SparseCat{Array{Symbol,1},Float64} distribution\n ┌ ┐ \n :a ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 1.0 \n └ ┘ "

0 comments on commit a96db23

Please sign in to comment.