Skip to content

Commit 215ab37

Browse files
committed
dump local, private, classes method if favour of CategoricalArrays.levels
1 parent 3132bd1 commit 215ab37

File tree

5 files changed

+8
-68
lines changed

5 files changed

+8
-68
lines changed

src/backends.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ If [`Sage`](@ref)`(multitarget=..., code_type=...)` has been implemented, then
3131
`observations.target` has an integer element type controlled by `code_type`, and we
3232
additionally have:
3333
34-
- `observations.classes`: A categorical vector of the ordered target classes, as actually
35-
seen in the user-supplied target, with the full pool of classes available by applying
34+
- `observations.classes`: A categorical vector of the ordered target levels, as actually
35+
seen in the user-supplied target, with the full pool of levels available by applying
3636
`Categorical.levels` to the result. The corresponding integer codes will be
3737
`sort(unique(observations.target))`.
3838

src/saffron.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function finalize(x, names, y, int) # here `int` is `levelcode` or `refcode` fu
150150
CategoricalArrays.CategoricalArray,
151151
SubArray{<:Any, <:Any, <:CategoricalArrays.CategoricalArray},
152152
} || throw(ERR_EXPECTED_CATEGORICAL)
153-
l = LearnDataFrontEnds.classes(y)
153+
l = CategoricalArrays.levels(y)
154154
u = unique(y)
155155
mask = map(in(u), l)
156156
_classes_seen = l[mask]

src/tools.jl

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -112,56 +112,6 @@ function decompose(X, v, _targets::NTuple)
112112
return swapdims(A, v), collect(names), swapdims(B, v)
113113
end
114114

115-
"""
116-
classes(x)
117-
118-
*Private method.*
119-
120-
Return, as a `CategoricalVector`, all the categorical elements with
121-
the same pool as `CategoricalValue` `x` (including `x`), with an
122-
ordering consistent with the pool. Note that `x in classes(x)` is
123-
always true.
124-
125-
Not to be confused with `levels(x.pool)`. See the example below.
126-
127-
Also, overloaded for `x` a `CategoricalArray`, `CategoricalPool`, and for views of
128-
`CategoricalArray`.
129-
130-
julia> v = categorical(['c', 'b', 'c', 'a'])
131-
4-element CategoricalArrays.CategoricalArray{Char,1,UInt32}:
132-
'c'
133-
'b'
134-
'c'
135-
'a'
136-
137-
julia> levels(v)
138-
3-element Array{Char,1}:
139-
'a'
140-
'b'
141-
'c'
142-
143-
julia> x = v[4]
144-
CategoricalArrays.CategoricalValue{Char,UInt32} 'a'
145-
146-
julia> classes(x)
147-
3-element CategoricalArrays.CategoricalArray{Char,1,UInt32}:
148-
'a'
149-
'b'
150-
'c'
151-
152-
julia> levels(x.pool)
153-
3-element Array{Char,1}:
154-
'a'
155-
'b'
156-
'c'
157-
158-
"""
159-
classes(p::CategoricalArrays.CategoricalPool) = [p[i] for i in 1:length(p)]
160-
classes(x::CategoricalArrays.CategoricalValue) = classes(CategoricalArrays.pool(x))
161-
classes(v::CategoricalArrays.CategoricalArray) = classes(CategoricalArrays.pool(v))
162-
classes(v::SubArray{<:Any, <:Any, <:CategoricalArrays.CategoricalArray}) = classes(parent(v))
163-
164-
165115
struct CategoricalDecoder{V,R}
166116
classes::CategoricalArrays.CategoricalVector{
167117
V,
@@ -193,7 +143,7 @@ pool as `x`.
193143
*Warning:* There is no guarantee that `levelcode.(d.(u)) == u` will always holds.
194144
195145
"""
196-
decoder(x) = CategoricalDecoder(classes(x))
146+
decoder(x) = CategoricalDecoder(CategoricalArrays.levels(x))
197147

198148
(d::CategoricalDecoder{V,R})(i::Integer) where {V,R} =
199149
CategoricalArrays.CategoricalValue{V,R}(d.classes[i])

test/backends.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import CategoricalArrays
77
y = [3, 2, 1]
88
names = [:x1, :x2]
99
ycat = CategoricalArrays.categorical(y)
10-
c = LearnDataFrontEnds.classes(ycat)
10+
c = CategoricalArrays.levels(ycat)
1111
d = LearnDataFrontEnds.decoder(ycat)
1212
mime = MIME"text/plain"()
1313

test/tools.jl

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import LearnDataFrontEnds: DoView, DontView, Multitarget, Unitarget
88
using CategoricalArrays
99
using Random
1010
using StableRNGs
11-
import LearnDataFrontEnds: classes, decoder
11+
import LearnDataFrontEnds: decoder
1212

13+
# developers, use this to work locally:
1314
# include("_some_learners.jl")
1415

1516
@testset "decompose" begin
@@ -79,17 +80,6 @@ end
7980

8081
rng = StableRNGs.StableRNG(123)
8182

82-
@testset "classes" begin
83-
v = categorical(collect("asqfasqffqsaaaa"), ordered=true)
84-
@test classes(v[1]) == levels(v)
85-
@test classes(v) == levels(v)
86-
levels!(v, reverse(levels(v)))
87-
@test classes(v[1]) == levels(v)
88-
@test classes(v) == levels(v)
89-
vsub = view(v, 1:2)
90-
@test classes(vsub) == classes(v)
91-
end
92-
9383
const int = CategoricalArrays.refcode
9484

9585
@testset "decoder" begin
@@ -123,7 +113,7 @@ const int = CategoricalArrays.refcode
123113
e = decoder(y)
124114
@test e.(int.(W)) == W
125115

126-
@test int.(classes(y)) == 1:length(classes(x))
116+
@test int.(levels(y)) == 1:length(levels(x))
127117

128118
v = categorical(['a', 'b', 'c'], ordered=true)
129119
end

0 commit comments

Comments
 (0)