|
123 | 123 |
|
124 | 124 | @testset "Recoding from $(typeof(x)) to categorical array with missing values" for
|
125 | 125 | x in (["a", missing, "c", "d"], CategoricalArray(["a", missing, "c", "d"]))
|
| 126 | + |
126 | 127 | # check that error is thrown
|
127 | 128 | y = Vector{String}(4)
|
128 | 129 | @test_throws MissingException recode!(y, x, "a", "c"=>"b")
|
|
159 | 160 | end
|
160 | 161 | end
|
161 | 162 |
|
162 |
| -@testset "Recoding array with missings, no default and with missing as a key pair from $(typeof(x)) to $(typeof(y))" for |
| 163 | +@testset "Collection in LHS recoding array with missings and no default from $(typeof(x)) to $(typeof(y))" for |
| 164 | + x in (["1", missing, "3", "4", "5"], CategoricalArray(["1", missing, "3", "4", "5"])), |
| 165 | + y in (similar(x), Array{Union{String, Missing}}(size(x)), |
| 166 | + CategoricalArray{Union{String, Missing}}(size(x)), x) |
| 167 | + |
| 168 | + z = @inferred recode!(y, x, ["3","4"]=>"2") |
| 169 | + @test y === z |
| 170 | + @test y ≅ ["1", missing, "2", "2", "5"] |
| 171 | + if isa(y, CategoricalArray) |
| 172 | + @test levels(y) == ["1", "5", "2"] |
| 173 | + @test !isordered(y) |
| 174 | + end |
| 175 | +end |
| 176 | + |
| 177 | +@testset "Recoding array with missings, default and with missing as a key pair from $(typeof(x)) to $(typeof(y))" for |
163 | 178 | x in (["a", missing, "c", "d"], CategoricalArray(["a", missing, "c", "d"])),
|
164 | 179 | y in (similar(x), Array{Union{String, Missing}}(size(x)),
|
165 | 180 | CategoricalArray{Union{String, Missing}}(size(x)), x)
|
|
173 | 188 | end
|
174 | 189 | end
|
175 | 190 |
|
| 191 | +@testset "Collection with missing in LHS recoding array with missings, default from $(typeof(x)) to $(typeof(y))" for |
| 192 | + x in (["a", missing, "c", "d"], CategoricalArray(["a", missing, "c", "d"])), |
| 193 | + y in (similar(x), Array{Union{String, Missing}}(size(x)), |
| 194 | + CategoricalArray{Union{String, Missing}}(size(x)), x) |
| 195 | + |
| 196 | + z = @inferred recode!(y, x, "a", [missing, "c"]=>"b") |
| 197 | + @test y === z |
| 198 | + @test y == ["a", "b", "b", "a"] |
| 199 | + if isa(y, CategoricalArray) |
| 200 | + @test levels(y) == ["b", "a"] |
| 201 | + @test !isordered(y) |
| 202 | + end |
| 203 | +end |
| 204 | + |
176 | 205 | @testset "Recoding array with missings, no default and with missing as a key pair from $(typeof(x)) to $(typeof(y))" for
|
177 | 206 | x in (["a", missing, "c", "d"], CategoricalArray(["a", missing, "c", "d"])),
|
178 | 207 | y in (similar(x), Array{Union{String, Missing}}(size(x)),
|
|
187 | 216 | end
|
188 | 217 | end
|
189 | 218 |
|
| 219 | +@testset "Collection with missing in LHS recoding array with missings, no default from $(typeof(x)) to $(typeof(y))" for |
| 220 | + x in (["a", missing, "c", "d"], CategoricalArray(["a", missing, "c", "d"])), |
| 221 | + y in (similar(x), Array{Union{String, Missing}}(size(x)), |
| 222 | + CategoricalArray{Union{String, Missing}}(size(x)), x) |
| 223 | + |
| 224 | + z = @inferred recode!(y, x, ["c", missing]=>"b") |
| 225 | + @test y === z |
| 226 | + @test y == ["a", "b", "b", "d"] |
| 227 | + if isa(y, CategoricalArray) |
| 228 | + @test levels(y) == ["a", "d", "b"] |
| 229 | + @test !isordered(y) |
| 230 | + end |
| 231 | +end |
| 232 | + |
190 | 233 | @testset "Recoding into an array of incompatible size from $(typeof(x)) to $(typeof(y))" for
|
191 | 234 | x in (["a", missing, "c", "d"], CategoricalArray(["a", missing, "c", "d"])),
|
192 | 235 | y in (similar(x, 0), Array{Union{String, Missing}}(0),
|
|
0 commit comments