Skip to content

Commit 5dd0717

Browse files
authored
fix the displayed indices in show(::OffsetRange) (#200)
* fix indices in show(::OffsetRange) * Do not show type of the parent range, display only the values and indices
1 parent 3a9b52f commit 5dd0717

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/OffsetArrays.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,8 @@ indexing is faster with ranges =#
367367
@propagate_inbounds Base.getindex(r::UnitRange{<:Integer}, s::IIUR) = IdentityUnitRange(r[no_offset_view(s)])
368368

369369
function Base.show(io::IO, r::OffsetRange)
370-
show(io, r.parent)
371-
o = r.offsets[1]
372-
print(io, " with indices ", o+1:o+length(r))
370+
show(io, UnitRange(r.parent))
371+
print(io, " with indices ", UnitRange(axes(r, 1)))
373372
end
374373
Base.show(io::IO, ::MIME"text/plain", r::OffsetRange) = show(io, r)
375374

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,12 @@ end
10031003
show(io, MIME"text/plain"(), OffsetArray(3:5, 0:2))
10041004
@test String(take!(io)) == "3:5 with indices 0:2"
10051005

1006+
# issue #198
1007+
r = axes(OffsetVector(1:10, -5), 1)
1008+
a = OffsetVector(r, 5)
1009+
show(io, a)
1010+
@test String(take!(io)) == "$(UnitRange(r)) with indices $(UnitRange(axes(a,1)))"
1011+
10061012
d = Diagonal([1,2,3])
10071013
Base.print_array(io, d)
10081014
s1 = String(take!(io))

0 commit comments

Comments
 (0)