From 21557721f2868ef50922f143763d9ee0ae064610 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 9 Feb 2021 12:54:30 +0400 Subject: [PATCH] Do not print delimiters twice in show(::OffsetMatrix) for matrices with certain shifted axes (#39522) --- base/arrayshow.jl | 5 +++-- test/offsetarray.jl | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/base/arrayshow.jl b/base/arrayshow.jl index 37adaf13f669e..ecf673da3a764 100644 --- a/base/arrayshow.jl +++ b/base/arrayshow.jl @@ -386,7 +386,8 @@ function _show_nonempty(io::IO, X::AbstractMatrix, prefix::String) nr, nc = length(indr), length(indc) rdots, cdots = false, false rr1, rr2 = UnitRange{Int}(indr), 1:0 - cr1, cr2 = UnitRange{Int}(indc), 1:0 + cr1 = UnitRange{Int}(indc) + cr2 = first(cr1) .+ (0:-1) if limit if nr > 4 rr1, rr2 = rr1[1:2], rr1[nr-1:nr] @@ -417,7 +418,7 @@ function _show_nonempty(io::IO, X::AbstractMatrix, prefix::String) end end end - last(rr) != nr && rdots && print(io, "\u2026 ; ") + last(rr) != last(indr) && rdots && print(io, "\u2026 ; ") end print(io, "]") end diff --git a/test/offsetarray.jl b/test/offsetarray.jl index ee75623e7a7c8..5deb442f36222 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -757,3 +757,22 @@ end @test a[ax[i]] == a[ax][i] end end + +@testset "show OffsetMatrix" begin + Y = reshape(1:25, 5, 5) + X = OffsetArray(Y, -2:2, -4:0) + + io = IOBuffer() + show(io, X) + strX = String(take!(io)) + show(io, Y) + strY = String(take!(io)) + @test strX == strY + + io_limit = IOContext(io, :limit => true) + show(io_limit, X) + strX = String(take!(io)) + show(io_limit, Y) + strY = String(take!(io)) + @test strX == strY +end