Skip to content

Commit

Permalink
Change indexin sentinel to nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Jan 20, 2018
1 parent 8aca8ce commit 8d97a94
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ indmin(a) = findmin(a)[2]
Return an array containing the highest index in `b` for
each value in `a` that is a member of `b`. The output
array contains 0 wherever `a` is not a member of `b`.
array contains `nothing` wherever `a` is not a member of `b`.
# Examples
```jldoctest
Expand All @@ -2178,7 +2178,7 @@ julia> indexin(a, b)
2
3
2
0
nothing
1
julia> indexin(b, a)
Expand All @@ -2189,8 +2189,8 @@ julia> indexin(b, a)
```
"""
function indexin(a, b::AbstractArray)
bdict = Dict(zip(b, 1:length(b)))
map(i -> get(bdict, i, 0), a)
bdict = Dict(zip(b, eachindex(b)))
map(i -> get(bdict, i, nothing), a)
end

function _findin(a, b)
Expand Down
6 changes: 3 additions & 3 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1394,9 +1394,9 @@ end
@test i7197() == (2,2)

# PR #8622 and general indexin tests
@test indexin([1,3,5,7], [5,4,3]) == [0,3,1,0]
@test indexin([1 3; 5 7], [5 4; 3 2]) == [0 2; 1 0]
@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [0,3,4,0]
@test indexin([1,3,5,7], [5,4,3]) == [nothing,3,1,nothing]
@test indexin([1 3; 5 7], [5 4; 3 2]) == [nothing 2; 1 nothing]
@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [nothing,3,4,nothing]
@test indexin(6, [1,3,6,6,2]) == 4
@test indexin([6], [1,3,6,6,2]) == [4]
@test indexin(3, 2:5) == 2
Expand Down

0 comments on commit 8d97a94

Please sign in to comment.