Skip to content

Commit

Permalink
add unsafe_getindex_notnull()
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed Jul 12, 2017
1 parent ca641b8 commit 766a4e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/CategoricalArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module CategoricalArrays
export categorical, compress, decompress, droplevels!, levels, levels!, isordered, ordered!, reftype
export cut, recode, recode!

using Compat
using Compat, NullableArrays

import NullableArrays: unsafe_getindex_notnull, unsafe_getvalue_notnull

include("typedefs.jl")

Expand Down
14 changes: 14 additions & 0 deletions src/nullablearray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ NullableCategoricalMatrix{T}(A::AbstractMatrix{T},
end
end

@inline NullableArrays.unsafe_getvalue_notnull(A::NullableCategoricalArray, I...) =
getindex(A.pool, getindex(A.refs, I...))

@inline function NullableArrays.unsafe_getindex_notnull(A::NullableCategoricalArray, I::Real...)
@boundscheck checkbounds(A, I...)
@inbounds r = A.refs[I...]

if isa(r, Array)
@inbounds return ordered!(arraytype(A)(r, deepcopy(A.pool)), isordered(A))
else
@inbounds return Nullable{eltype(eltype(A))}(A.pool[r])
end
end

@inline function setindex!(A::NullableCategoricalArray, v::Nullable, I::Real...)
@boundscheck checkbounds(A, I...)
if isnull(v)
Expand Down

0 comments on commit 766a4e6

Please sign in to comment.