@@ -26,6 +26,10 @@ using CategoricalArrays: DefaultRefType, level, reftype, leveltype, catvalue, is
26
26
@test reftype (typeof (v1)) === DefaultRefType
27
27
@test v1 isa CategoricalArrays. CategoricalValue{Int, DefaultRefType}
28
28
29
+ @test convert (Int, v1) === 1
30
+ @test convert (Int, v2) === 2
31
+ @test convert (Int, v3) === 3
32
+
29
33
@test convert (Int32, v1) === Int32 (1 )
30
34
@test convert (Int32, v2) === Int32 (2 )
31
35
@test convert (Int32, v3) === Int32 (3 )
@@ -55,7 +59,56 @@ using CategoricalArrays: DefaultRefType, level, reftype, leveltype, catvalue, is
55
59
@test promote (1 , v1) === (1 , 1 )
56
60
@test promote (1.0 , v1) === (1.0 , 1.0 )
57
61
@test promote (0x1 , v1) === (1 , 1 )
62
+ end
63
+
64
+ @testset " convert() for CategoricalPool{String, DefaultRefType} and values" begin
65
+ pool = CategoricalPool ([" a" , " b" , " c" ])
66
+ @test convert (CategoricalPool{String, DefaultRefType}, pool) === pool
67
+ @test convert (CategoricalPool{String}, pool) === pool
68
+ @test convert (CategoricalPool, pool) === pool
69
+ convert (CategoricalPool{String, UInt8}, pool)
70
+
71
+ v1 = catvalue (1 , pool)
72
+ v2 = catvalue (2 , pool)
73
+ v3 = catvalue (3 , pool)
74
+ @test iscatvalue (v1)
75
+ @test iscatvalue (typeof (v1))
76
+ @test eltype (v1) === Char
77
+ @test eltype (typeof (v1)) === Char
78
+ @test leveltype (v1) === String
79
+ @test leveltype (typeof (v1)) === String
80
+ @test reftype (v1) === DefaultRefType
81
+ @test reftype (typeof (v1)) === DefaultRefType
82
+ @test v1 isa CategoricalArrays. CategoricalString{DefaultRefType}
83
+
84
+ @test convert (String, v1) == " a"
85
+ @test convert (String, v2) == " b"
86
+ @test convert (String, v3) == " c"
87
+
88
+ @test convert (AbstractString, v1) == " a"
89
+ @test convert (AbstractString, v2) == " b"
90
+ @test convert (AbstractString, v3) == " c"
91
+
92
+ @test convert (CategoricalString, v1) === v1
93
+ @test convert (CategoricalString{DefaultRefType}, v1) === v1
94
+
95
+ @test convert (Any, v1) === v1
96
+ @test convert (Any, v2) === v2
97
+ @test convert (Any, v3) === v3
98
+
99
+ for T in (typeof (v1), CatValue, CategoricalString, CategoricalString{DefaultRefType}),
100
+ U in (Missing, Nothing)
101
+ @test convert (Union{T, U}, v1) === v1
102
+ @test convert (Union{T, U}, v2) === v2
103
+ @test convert (Union{T, U}, v3) === v3
104
+ end
105
+
106
+ @test get (v1) === " a"
107
+ @test get (v2) === " b"
108
+ @test get (v3) === " c"
109
+ end
58
110
111
+ @testset " promote_type" begin
59
112
# Tests that return Any are due to JuliaLang/julia#29348
60
113
# It is not clear what would be the most appropriate promotion type for them,
61
114
# but at least they should not throw an error
0 commit comments