Skip to content

Commit

Permalink
Merge fed2f16 into f0e31c4
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Oct 14, 2020
2 parents f0e31c4 + fed2f16 commit aaaab54
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/array.jl
Expand Up @@ -1066,7 +1066,7 @@ Base.IndexStyle(::Type{<: CategoricalRefPool}) = Base.IndexLinear()

@inline function Base.getindex(x::CategoricalRefPool, i::Int)
@boundscheck checkbounds(x, i)
i > 0 ? @inbounds(x.pool[i]) : missing
i > 0 ? get(@inbounds(x.pool[i])) : missing
end

Base.size(x::CategoricalRefPool{T}) where {T} = (length(x.pool) + (T >: Missing),)
Expand All @@ -1076,7 +1076,7 @@ Base.LinearIndices(x::CategoricalRefPool) = axes(x, 1)

DataAPI.refarray(A::CatArrOrSub) = refs(A)
DataAPI.refpool(A::CatArrOrSub{T}) where {T} =
CategoricalRefPool{eltype(A), typeof(pool(A))}(pool(A))
CategoricalRefPool{leveltype(eltype(A)), typeof(pool(A))}(pool(A))

@inline function DataAPI.refvalue(A::CatArrOrSub{T}, i::Integer) where T
@boundscheck checkindex(Bool, (T >: Missing ? 0 : 1):length(pool(A)), i) ||
Expand Down
1 change: 1 addition & 0 deletions src/value.jl
Expand Up @@ -2,6 +2,7 @@ CategoricalValue(level::Integer, pool::CategoricalPool{T, R}) where {T, R} =
CategoricalValue(convert(R, level), pool)

leveltype(::Type{<:CategoricalValue{T}}) where {T} = T
leveltype(::Type{Union{Missing, C}}) where {C <: CategoricalValue} = Union{Missing, leveltype(C)}
leveltype(::Type{T}) where {T} = T
leveltype(x::Any) = leveltype(typeof(x))
# to fix ambiguity
Expand Down
2 changes: 1 addition & 1 deletion test/13_arraycommon.jl
Expand Up @@ -2042,7 +2042,7 @@ end
end

rp = DataAPI.refpool(y)
@test rp isa AbstractVector{eltype(y)}
@test rp isa AbstractVector{CategoricalArrays.leveltype(eltype(y))}
@test Base.IndexStyle(rp) isa Base.IndexLinear
@test LinearIndices(rp) == axes(rp, 1)
if eltype(y) >: Missing
Expand Down

0 comments on commit aaaab54

Please sign in to comment.