Skip to content

Commit

Permalink
Do not print delimiters twice in show(::OffsetMatrix) for matrices wi…
Browse files Browse the repository at this point in the history
…th certain shifted axes (#39522)
  • Loading branch information
jishnub authored Feb 9, 2021
1 parent 8458ca1 commit 2155772
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/arrayshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2155772

Please sign in to comment.