Skip to content

Commit

Permalink
Make boolean indexing of Index strict (#1326)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored and nalimilan committed Dec 24, 2017
1 parent 4abe138 commit f24817d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/other/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ Base.getindex(x::Index, idx::Symbol) = x.lookup[idx]
Base.getindex(x::AbstractIndex, idx::Real) = Int(idx)
Base.getindex(x::AbstractIndex, idx::AbstractVector{Union{Bool, Missing}}) =
getindex(x, collect(Missings.replace(idx, false)))
Base.getindex(x::AbstractIndex, idx::AbstractVector{Bool}) = find(idx)
function Base.getindex(x::AbstractIndex, idx::AbstractVector{Bool})
length(x) == length(idx) || throw(BoundsError(x, idx))
find(idx)
end
Base.getindex(x::AbstractIndex, idx::AbstractVector{T}) where {T >: Missing} =
getindex(x, collect(skipmissing(idx)))
Base.getindex(x::AbstractIndex, idx::AbstractRange) = [idx;]
Expand Down
8 changes: 5 additions & 3 deletions test/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ push!(i, :B)
inds = Any[1,
1.0,
:A,
[true],
trues(1),
[true, false],
[1],
[1.0],
1:1,
1.0:1.0,
[:A],
Union{Bool, Missing}[true],
Union{Bool, Missing}[true, false],
Union{Int, Missing}[1],
Union{Float64, Missing}[1.0],
Union{Symbol, Missing}[:A]]
Expand All @@ -28,6 +27,9 @@ for ind in inds
end
end

@test_throws BoundsError i[[true]]
@test_throws BoundsError i[[true, false, true]]

@test names(i) == [:A,:B]
@test names!(i, [:a,:a], allow_duplicates=true) == Index([:a,:a_1])
@test_throws ArgumentError names!(i, [:a,:a])
Expand Down

0 comments on commit f24817d

Please sign in to comment.