|
169 | 169 | @test scitype_union(coerce([:x, :y], Finite)) === Multiclass{2}
|
170 | 170 | @test scitype_union(@test_logs((:warn, r"Missing values encountered"),
|
171 | 171 | coerce([:x, :y, missing], Finite))) ===
|
172 |
| - Union{Missing, Multiclass{2}} |
| 172 | + Union{Missing, Multiclass{2}} |
| 173 | + |
| 174 | + # More finite conversions (to check resolution of #48): |
| 175 | + y = categorical([1, 2, 3, missing]) # unordered |
| 176 | + yc = coerce(y, OrderedFactor) |
| 177 | + @test isordered(yc) |
| 178 | + @test yc[1].pool.ordered |
| 179 | + scitype(y) == AbstractVector{OrderedFactor{2}} |
| 180 | + scitype_union(y) == OrderedFactor{2} |
| 181 | + |
173 | 182 | end
|
174 | 183 |
|
175 | 184 | @testset "coercion works for arrays too" begin
|
|
215 | 224 | @test eltype(v2c) <: CategoricalValue{Char}
|
216 | 225 | end
|
217 | 226 |
|
| 227 | +@testset "Cat->Count,Continuous (mlj)" begin |
| 228 | + a = categorical(["a","b","a","b",missing]) |
| 229 | + a1 = coerce(a, Union{Count,Missing}) |
| 230 | + @test scitype_union(a1) == Union{Missing,Count} |
| 231 | + @test all(skipmissing(a1 .== [1, 2, 1, 2, missing])) |
| 232 | + a1 = coerce(a, Union{Continuous,Missing}) |
| 233 | + @test scitype_union(a1) == Union{Missing,Continuous} |
| 234 | + @test all(skipmissing(a1 .== [1., 2., 1., 2., missing])) |
| 235 | + |
| 236 | + # XXX |
| 237 | + |
| 238 | + y = categorical(1:10, ordered=true) |
| 239 | + new_order = [4, 10, 9, 7, 6, 2, 8, 3, 1, 5] |
| 240 | + levels!(y, new_order) |
| 241 | + @test all(coerce(y, Count) .== sortperm(new_order)) |
| 242 | + @test all(coerce(y, Count) .== [9, 6, 8, 1, 10, 5, 4, 7, 3, 2]) |
| 243 | + |
| 244 | + y = categorical([1:10..., missing, 11], ordered=true) |
| 245 | + @test all(skipmissing(coerce(y, Union{Continuous, Missing}) .== float.([1:10...,missing,11]))) |
| 246 | +end |
| 247 | + |
218 | 248 | include("autotype.jl")
|
0 commit comments