@@ -6,28 +6,27 @@ const SupportedTypes = Union{AbstractString, AbstractChar, Number}
6
6
# Type params:
7
7
# * `T` type of categorized values
8
8
# * `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 }
11
10
levels:: Vector{T} # category levels ordered by their reference codes
12
11
invindex:: Dict{T, R} # map from category levels to their reference codes
13
12
ordered:: Bool # whether levels can be compared using <
14
13
hash:: Union{UInt, Nothing} # hash of levels
15
14
subsetof:: Ptr{Nothing} # last seen strict superset pool
16
15
equalto:: Ptr{Nothing} # last seen equal pool
17
16
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}
20
19
if length (levels) > typemax (R)
21
20
throw (LevelsException {T, R} (levels[Int (typemax (R))+ 1 : end ]))
22
21
end
23
22
invindex = Dict {T, R} (v => i for (i, v) in enumerate (levels))
24
23
if length (invindex) != length (levels)
25
24
throw (ArgumentError (" Duplicate entries are not allowed in levels" ))
26
25
end
27
- CategoricalPool {T, R, V } (levels, invindex, ordered)
26
+ CategoricalPool {T, R} (levels, invindex, ordered)
28
27
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}
31
30
levels = Vector {T} (undef, length (invindex))
32
31
# If invindex contains non consecutive values, a BoundsError will be thrown
33
32
try
@@ -40,18 +39,12 @@ mutable struct CategoricalPool{T <: SupportedTypes, R <: Integer, V}
40
39
if length (invindex) > typemax (R)
41
40
throw (LevelsException {T, R} (levels[typemax (R)+ 1 : end ]))
42
41
end
43
- CategoricalPool {T, R, V } (levels, invindex, ordered)
42
+ CategoricalPool {T, R} (levels, invindex, ordered)
44
43
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}
55
48
pool = new (levels, invindex, ordered, hash, C_NULL , C_NULL )
56
49
return pool
57
50
end
@@ -77,7 +70,7 @@ the order of the pool's [`levels`](@ref DataAPI.levels) is used rather than the
77
70
ordering of values of type `T`.
78
71
"""
79
72
struct CategoricalValue{T <: SupportedTypes , R <: Integer }
80
- pool:: CategoricalPool{T, R, CategoricalValue{T, R} }
73
+ pool:: CategoricalPool{T, R}
81
74
ref:: R
82
75
end
83
76
@@ -98,14 +91,14 @@ const AbstractCategoricalMatrix{T, R, V, C, U} = AbstractCategoricalArray{T, 2,
98
91
99
92
mutable struct CategoricalArray{T, N, R <: Integer , V, C, U} <: AbstractCategoricalArray{T, N, R, V, C, U}
100
93
refs:: Array{R, N}
101
- pool:: CategoricalPool{V, R, C }
94
+ pool:: CategoricalPool{V, R}
102
95
103
96
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}
106
99
T === V || T == Union{V, Missing} || throw (ArgumentError (" T ($T ) must be equal to $V or Union{$V , Missing}" ))
107
100
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)
109
102
end
110
103
end
111
104
const CategoricalVector{T, R <: Integer , V, C, U} = CategoricalArray{T, 1 , R, V, C, U}
0 commit comments