Skip to content

Commit ca1423c

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

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

base/array.jl

+6-6
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
@@ -2173,24 +2173,24 @@ julia> a = ['a', 'b', 'c', 'b', 'd', 'a']
21732173
julia> b = ['a', 'b', 'c']
21742174
21752175
julia> indexin(a, b)
2176-
6-element Array{Int64,1}:
2176+
6-element Array{Union{Nothing, Int64},1}:
21772177
1
21782178
2
21792179
3
21802180
2
2181-
0
2181+
nothing
21822182
1
21832183
21842184
julia> indexin(b, a)
2185-
3-element Array{Int64,1}:
2185+
3-element Array{Union{Nothing, Int64},1}:
21862186
6
21872187
4
21882188
3
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, keys(b)))
2193+
map(i -> get(bdict, i, nothing), a)
21942194
end
21952195

21962196
function _findin(a, b)

test/arrayops.jl

+3-3
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 CartesianIndex(2, 1); CartesianIndex(1, 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)