Skip to content

Commit c5db161

Browse files
committed
make classes(v) work for views of categorical arrays #17
1 parent c5ca9a2 commit c5db161

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/utilities.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ always true.
2121
2222
Not to be confused with `levels(x.pool)`. See the example below.
2323
24-
Also, overloaded for `x` a `CategoricalArray` or `CategoricalPool`.
24+
Also, overloaded for `x` a `CategoricalArray`, `CategoricalPool`, and
25+
for views of `CategoricalArray`.
2526
2627
**Private method.*
2728
@@ -57,7 +58,7 @@ Also, overloaded for `x` a `CategoricalArray` or `CategoricalPool`.
5758
classes(p::CategoricalPool) = [p[i] for i in 1:length(p)]
5859
classes(x::CategoricalValue) = classes(CategoricalArrays.pool(x))
5960
classes(v::CategoricalArray) = classes(CategoricalArrays.pool(v))
60-
61+
classes(v::SubArray{<:Any, <:Any, <:CategoricalArray}) = classes(parent(v))
6162

6263
# # CATEGORICAL VALUES TO INTEGERS
6364

test/utilities.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import CategoricalDistributions: classes, transform, decoder, int
1717
levels!(v, reverse(levels(v)))
1818
@test classes(v[1]) == levels(v)
1919
@test classes(v) == levels(v)
20+
vsub = view(v, 1:2)
21+
@test classes(vsub) == classes(v)
2022
end
2123

2224
@testset "int, classes, decoder" begin

0 commit comments

Comments
 (0)