From e4eece133d49a2176793a397b51824626e5e9d0f Mon Sep 17 00:00:00 2001 From: Zachary Sunberg Date: Tue, 11 Jun 2019 11:06:17 -0700 Subject: [PATCH] fixed bug that prints even when not necessary --- src/distributions/pretty_printing.jl | 2 +- test/test_pretty_printing.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/distributions/pretty_printing.jl b/src/distributions/pretty_printing.jl index da617dd..0577f65 100644 --- a/src/distributions/pretty_printing.jl +++ b/src/distributions/pretty_printing.jl @@ -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) diff --git a/test/test_pretty_printing.jl b/test/test_pretty_printing.jl index 6ac8fe5..7752ab7 100644 --- a/test/test_pretty_printing.jl +++ b/test/test_pretty_printing.jl @@ -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 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 0.94 \n └ ┘ " + +# test that it doesn't print 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 └ ┘ "