diff --git a/src/InvertedIndices.jl b/src/InvertedIndices.jl index 8754470..80ec12a 100644 --- a/src/InvertedIndices.jl +++ b/src/InvertedIndices.jl @@ -73,7 +73,12 @@ _should_skip(s::CartesianIndex{1}, p::Integer) = s.I[1] == p @inline Base.ensure_indexable(I::Tuple{InvertedIndexIterator, Vararg{Any}}) = (collect(I[1]), Base.ensure_indexable(tail(I))...) -Base.show(io::IO, I::InvertedIndexIterator) = show(io, collect(I)) +# This is a little hacky, but we display InvertedIndexIterators like the `Not`s they come from +function Base.show(io::IO, I::InvertedIndexIterator) + print(io, "Not(") + show(io, I.skips) + print(io, ")") +end # Inverted indices must be sorted and unique to ensure that iterating over # them and the axes simultaneously will work appropriately. Doing this fully diff --git a/test/runtests.jl b/test/runtests.jl index 1ab6fff..98b6b96 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -99,5 +99,8 @@ end end @testset "Utilities" begin - @test sprint(show, InvertedIndices.InvertedIndexIterator([2,4], 1:5)) == "[1, 3, 5]" + @test sprint(show, InvertedIndices.InvertedIndexIterator([2,4], 1:5)) == "Not([2, 4])" + A = [1] + ex = try A[Not(2,3)] catch ex; ex end + @test occursin("Not([2, 3])", sprint(Base.showerror, ex)) end