@@ -6,28 +6,27 @@ const SupportedTypes = Union{AbstractString, AbstractChar, Number}
66# Type params:
77# * `T` type of categorized values
88# * `R` integer type for referencing category levels
9- # * `V` categorical value type
10- mutable struct CategoricalPool{T <: SupportedTypes , R <: Integer , V}
9+ mutable struct CategoricalPool{T <: SupportedTypes , R <: Integer }
1110 levels:: Vector{T} # category levels ordered by their reference codes
1211 invindex:: Dict{T, R} # map from category levels to their reference codes
1312 ordered:: Bool # whether levels can be compared using <
1413 hash:: Union{UInt, Nothing} # hash of levels
1514 subsetof:: Ptr{Nothing} # last seen strict superset pool
1615 equalto:: Ptr{Nothing} # last seen equal pool
1716
18- function CategoricalPool {T, R, V } (levels:: Vector{T} ,
19- ordered:: Bool ) where {T, R, V }
17+ function CategoricalPool {T, R} (levels:: Vector{T} ,
18+ ordered:: Bool ) where {T, R}
2019 if length (levels) > typemax (R)
2120 throw (LevelsException {T, R} (levels[Int (typemax (R))+ 1 : end ]))
2221 end
2322 invindex = Dict {T, R} (v => i for (i, v) in enumerate (levels))
2423 if length (invindex) != length (levels)
2524 throw (ArgumentError (" Duplicate entries are not allowed in levels" ))
2625 end
27- CategoricalPool {T, R, V } (levels, invindex, ordered)
26+ CategoricalPool {T, R} (levels, invindex, ordered)
2827 end
29- function CategoricalPool {T, R, V } (invindex:: Dict{T, R} ,
30- ordered:: Bool ) where {T, R, V }
28+ function CategoricalPool {T, R} (invindex:: Dict{T, R} ,
29+ ordered:: Bool ) where {T, R}
3130 levels = Vector {T} (undef, length (invindex))
3231 # If invindex contains non consecutive values, a BoundsError will be thrown
3332 try
@@ -40,18 +39,12 @@ mutable struct CategoricalPool{T <: SupportedTypes, R <: Integer, V}
4039 if length (invindex) > typemax (R)
4140 throw (LevelsException {T, R} (levels[typemax (R)+ 1 : end ]))
4241 end
43- CategoricalPool {T, R, V } (levels, invindex, ordered)
42+ CategoricalPool {T, R} (levels, invindex, ordered)
4443 end
45- function CategoricalPool {T, R, V} (levels:: Vector{T} ,
46- invindex:: Dict{T, R} ,
47- ordered:: Bool ,
48- hash:: Union{UInt, Nothing} = nothing ) where {T, R, V}
49- if ! (V <: CategoricalValue )
50- throw (ArgumentError (" Type $V is not a categorical value type" ))
51- end
52- if V != = CategoricalValue{T, R}
53- throw (ArgumentError (" V must be CategoricalValue{T, R}" ))
54- end
44+ function CategoricalPool {T, R} (levels:: Vector{T} ,
45+ invindex:: Dict{T, R} ,
46+ ordered:: Bool ,
47+ hash:: Union{UInt, Nothing} = nothing ) where {T, R}
5548 pool = new (levels, invindex, ordered, hash, C_NULL , C_NULL )
5649 return pool
5750 end
@@ -77,7 +70,7 @@ the order of the pool's [`levels`](@ref DataAPI.levels) is used rather than the
7770ordering of values of type `T`.
7871"""
7972struct CategoricalValue{T <: SupportedTypes , R <: Integer }
80- pool:: CategoricalPool{T, R, CategoricalValue{T, R} }
73+ pool:: CategoricalPool{T, R}
8174 ref:: R
8275end
8376
@@ -98,14 +91,14 @@ const AbstractCategoricalMatrix{T, R, V, C, U} = AbstractCategoricalArray{T, 2,
9891
9992mutable struct CategoricalArray{T, N, R <: Integer , V, C, U} <: AbstractCategoricalArray{T, N, R, V, C, U}
10093 refs:: Array{R, N}
101- pool:: CategoricalPool{V, R, C }
94+ pool:: CategoricalPool{V, R}
10295
10396 function CategoricalArray {T, N} (refs:: Array{R, N} ,
104- pool:: CategoricalPool{V, R, C } ) where
105- {T, N, R <: Integer , V, C }
97+ pool:: CategoricalPool{V, R} ) where
98+ {T, N, R <: Integer , V}
10699 T === V || T == Union{V, Missing} || throw (ArgumentError (" T ($T ) must be equal to $V or Union{$V , Missing}" ))
107100 U = T >: Missing ? Missing : Union{}
108- new {T, N, R, V, C , U} (refs, pool)
101+ new {T, N, R, V, CategoricalValue{V, R} , U} (refs, pool)
109102 end
110103end
111104const CategoricalVector{T, R <: Integer , V, C, U} = CategoricalArray{T, 1 , R, V, C, U}
0 commit comments