Skip to content

Commit 8d97a94

Browse files
committed
Change indexin sentinel to nothing
1 parent 8aca8ce commit 8d97a94

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

base/array.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ indmin(a) = findmin(a)[2]
21642164
21652165
Return an array containing the highest index in `b` for
21662166
each value in `a` that is a member of `b`. The output
2167-
array contains 0 wherever `a` is not a member of `b`.
2167+
array contains `nothing` wherever `a` is not a member of `b`.
21682168
21692169
# Examples
21702170
```jldoctest
@@ -2178,7 +2178,7 @@ julia> indexin(a, b)
21782178
2
21792179
3
21802180
2
2181-
0
2181+
nothing
21822182
1
21832183
21842184
julia> indexin(b, a)
@@ -2189,8 +2189,8 @@ julia> indexin(b, a)
21892189
```
21902190
"""
21912191
function indexin(a, b::AbstractArray)
2192-
bdict = Dict(zip(b, 1:length(b)))
2193-
map(i -> get(bdict, i, 0), a)
2192+
bdict = Dict(zip(b, eachindex(b)))
2193+
map(i -> get(bdict, i, nothing), a)
21942194
end
21952195

21962196
function _findin(a, b)

test/arrayops.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,9 +1394,9 @@ end
13941394
@test i7197() == (2,2)
13951395

13961396
# PR #8622 and general indexin tests
1397-
@test indexin([1,3,5,7], [5,4,3]) == [0,3,1,0]
1398-
@test indexin([1 3; 5 7], [5 4; 3 2]) == [0 2; 1 0]
1399-
@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [0,3,4,0]
1397+
@test indexin([1,3,5,7], [5,4,3]) == [nothing,3,1,nothing]
1398+
@test indexin([1 3; 5 7], [5 4; 3 2]) == [nothing 2; 1 nothing]
1399+
@test indexin((2 * x + 1 for x in 0:3), [5,4,3,5,6]) == [nothing,3,4,nothing]
14001400
@test indexin(6, [1,3,6,6,2]) == 4
14011401
@test indexin([6], [1,3,6,6,2]) == [4]
14021402
@test indexin(3, 2:5) == 2

0 commit comments

Comments
 (0)