Skip to content

Commit ca8abfe

Browse files
authored
Fix show_vector for long offset arrays with :limit=true (#31642)
Fixes #31641
1 parent dd45fac commit ca8abfe

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

base/arrayshow.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,11 @@ function show_vector(io::IO, v, opn='[', cls=']')
434434
io = IOContext(io, :typeinfo => eltype(v))
435435
limited = get(io, :limit, false)
436436
if limited && length(v) > 20
437-
inds = axes1(v)
438-
show_delim_array(io, v, opn, ",", "", false, inds[1], inds[1]+9)
437+
axs1 = axes1(v)
438+
f, l = first(axs1), last(axs1)
439+
show_delim_array(io, v, opn, ",", "", false, f, f+9)
439440
print(io, "")
440-
show_delim_array(io, v, "", ",", cls, false, inds[end-9], inds[end])
441+
show_delim_array(io, v, "", ",", cls, false, l-9, l)
441442
else
442443
show_delim_array(io, v, opn, ",", cls, false)
443444
end

test/offsetarray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ cmp_showf(Base.print_matrix, io, OffsetArray(rand(10^3,5), (10,-9))) # column
203203
cmp_showf(Base.print_matrix, io, OffsetArray(rand(5,10^3), (10,-9))) # rows fit
204204
cmp_showf(Base.print_matrix, io, OffsetArray(rand(10^3,10^3), (10,-9))) # neither fits
205205
cmp_showf(Base.print_matrix, io, OffsetArray(reshape(range(-0.212121212121, stop=2/11, length=3*29), 3, 29), (-2, -15)); options=(:displaysize=>(53,210),))
206+
cmp_showf(show, io, OffsetArray(collect(1:100), (100,))) # issue #31641
207+
206208
targets1 = ["0-dimensional $OAs_name.OffsetArray{Float64,0,Array{Float64,0}}:\n1.0",
207209
"1-element $OAs_name.OffsetArray{Float64,1,Array{Float64,1}} with indices 2:2:\n 1.0",
208210
"1×1 $OAs_name.OffsetArray{Float64,2,Array{Float64,2}} with indices 2:2×3:3:\n 1.0",

0 commit comments

Comments
 (0)