@@ -1336,7 +1336,7 @@ end
1336
1336
z = Array (y)
1337
1337
@test typeof (x) == typeof (z)
1338
1338
@test z == x
1339
- z = Array (view (x , 1 : 4 ))
1339
+ z = Array (view (y , 1 : 4 ))
1340
1340
@test typeof (x) == typeof (z)
1341
1341
@test z == x
1342
1342
@@ -1345,7 +1345,7 @@ end
1345
1345
z = Array (y)
1346
1346
@test typeof (x) == typeof (z)
1347
1347
@test z ≅ x
1348
- z = Array (view (x , 1 : 4 ))
1348
+ z = Array (view (y , 1 : 4 ))
1349
1349
@test typeof (x) == typeof (z)
1350
1350
@test z ≅ x
1351
1351
@@ -1354,7 +1354,7 @@ end
1354
1354
z = Vector (y)
1355
1355
@test typeof (x) == typeof (z)
1356
1356
@test z == x
1357
- z = Vector (view (x , 1 : 4 ))
1357
+ z = Vector (view (y , 1 : 4 ))
1358
1358
@test typeof (x) == typeof (z)
1359
1359
@test z == x
1360
1360
@@ -1363,7 +1363,7 @@ end
1363
1363
z = Vector (y)
1364
1364
@test typeof (x) == typeof (z)
1365
1365
@test z ≅ x
1366
- z = Vector (view (x , 1 : 4 ))
1366
+ z = Vector (view (y , 1 : 4 ))
1367
1367
@test typeof (x) == typeof (z)
1368
1368
@test z ≅ x
1369
1369
@@ -1372,7 +1372,7 @@ end
1372
1372
z = Matrix (y)
1373
1373
@test typeof (x) == typeof (z)
1374
1374
@test z == x
1375
- z = Matrix (view (x , :, 1 : 4 ))
1375
+ z = Matrix (view (y , :, 1 : 4 ))
1376
1376
@test typeof (x) == typeof (z)
1377
1377
@test z == x
1378
1378
@@ -1381,7 +1381,7 @@ end
1381
1381
z = Matrix (y)
1382
1382
@test typeof (x) == typeof (z)
1383
1383
@test z ≅ x
1384
- z = Matrix (view (x , :, 1 : 4 ))
1384
+ z = Matrix (view (y , :, 1 : 4 ))
1385
1385
@test typeof (x) == typeof (z)
1386
1386
@test z ≅ x
1387
1387
end
@@ -1392,7 +1392,7 @@ end
1392
1392
z = convert (Array, y)
1393
1393
@test typeof (x) == typeof (z)
1394
1394
@test z == x
1395
- z = Array ( view (x , 1 : 4 ))
1395
+ z = convert (Array, view (y , 1 : 4 ))
1396
1396
@test typeof (x) == typeof (z)
1397
1397
@test z == x
1398
1398
@@ -1401,7 +1401,7 @@ end
1401
1401
z = convert (Array, y)
1402
1402
@test typeof (x) == typeof (z)
1403
1403
@test z ≅ x
1404
- z = Array ( view (x , 1 : 4 ))
1404
+ z = convert (Array, view (y , 1 : 4 ))
1405
1405
@test typeof (x) == typeof (z)
1406
1406
@test z ≅ x
1407
1407
@@ -1410,7 +1410,7 @@ end
1410
1410
z = convert (Vector, y)
1411
1411
@test typeof (x) == typeof (z)
1412
1412
@test z == x
1413
- z = Vector ( view (x , 1 : 4 ))
1413
+ z = convert (Vector, view (y , 1 : 4 ))
1414
1414
@test typeof (x) == typeof (z)
1415
1415
@test z == x
1416
1416
@@ -1419,7 +1419,7 @@ end
1419
1419
z = convert (Vector, y)
1420
1420
@test typeof (x) == typeof (z)
1421
1421
@test z ≅ x
1422
- z = Vector ( view (x , 1 : 4 ))
1422
+ z = convert (Vector, view (y , 1 : 4 ))
1423
1423
@test typeof (x) == typeof (z)
1424
1424
@test z ≅ x
1425
1425
@@ -1428,7 +1428,7 @@ end
1428
1428
z = convert (Matrix, y)
1429
1429
@test typeof (x) == typeof (z)
1430
1430
@test z == x
1431
- z = Matrix ( view (x , :, 1 : 4 ))
1431
+ z = convert (Matrix, view (y , :, 1 : 4 ))
1432
1432
@test typeof (x) == typeof (z)
1433
1433
@test z == x
1434
1434
@@ -1437,7 +1437,7 @@ end
1437
1437
z = convert (Matrix, y)
1438
1438
@test typeof (x) == typeof (z)
1439
1439
@test z ≅ x
1440
- z = Matrix ( view (x , :, 1 : 4 ))
1440
+ z = convert (Matrix, view (y , :, 1 : 4 ))
1441
1441
@test typeof (x) == typeof (z)
1442
1442
@test z ≅ x
1443
1443
end
@@ -1462,6 +1462,119 @@ end
1462
1462
@test z ≅ x
1463
1463
end
1464
1464
1465
+ @testset " Array(::CatArrOrSub{T<:CategoricalValue}) produces Array{T}" begin
1466
+ x = [1 ,1 ,2 ,2 ]
1467
+ y = categorical (x)
1468
+ z = Array {eltype(y)} (y)
1469
+ @test z isa Array{eltype (y)}
1470
+ @test z == x
1471
+ z = Array {eltype(y)} (view (y, 1 : 4 ))
1472
+ @test z isa Array{eltype (y)}
1473
+ @test z == x
1474
+
1475
+ x = [1 ,1 ,2 ,missing ]
1476
+ y = categorical (x)
1477
+ z = Array {eltype(y)} (y)
1478
+ @test z isa Array{eltype (y)}
1479
+ @test z ≅ x
1480
+ z = Array {eltype(y)} (view (y, 1 : 4 ))
1481
+ @test z isa Array{eltype (y)}
1482
+ @test z ≅ x
1483
+
1484
+ x = [1 ,1 ,2 ,2 ]
1485
+ y = categorical (x)
1486
+ z = Vector {eltype(y)} (y)
1487
+ @test z isa Vector{eltype (y)}
1488
+ @test z == x
1489
+ z = Vector {eltype(y)} (view (y, 1 : 4 ))
1490
+ @test z isa Vector{eltype (y)}
1491
+ @test z == x
1492
+
1493
+ x = [1 ,1 ,2 ,missing ]
1494
+ y = categorical (x)
1495
+ z = Vector {eltype(y)} (y)
1496
+ @test z isa Vector{eltype (y)}
1497
+ @test z ≅ x
1498
+ z = Vector {eltype(y)} (view (y, 1 : 4 ))
1499
+ @test z isa Vector{eltype (y)}
1500
+ @test z ≅ x
1501
+
1502
+ x = [1 1 2 2 ]
1503
+ y = categorical (x)
1504
+ z = Matrix {eltype(y)} (y)
1505
+ @test z isa Matrix{eltype (y)}
1506
+ @test z == x
1507
+ z = Matrix {eltype(y)} (view (y, :, 1 : 4 ))
1508
+ @test z isa Matrix{eltype (y)}
1509
+ @test z == x
1510
+
1511
+ x = [1 1 2 missing ]
1512
+ y = categorical (x)
1513
+ z = Matrix {eltype(y)} (y)
1514
+ @test z isa Matrix{eltype (y)}
1515
+ @test z ≅ x
1516
+ z = Matrix {eltype(y)} (view (y, :, 1 : 4 ))
1517
+ @test z isa Matrix{eltype (y)}
1518
+ @test z ≅ x
1519
+ end
1520
+
1521
+
1522
+ @testset " convert(Array, ::CatArrOrSub{T<:CategoricalValue}) produces Array{T}" begin
1523
+ x = [1 ,1 ,2 ,2 ]
1524
+ y = categorical (x)
1525
+ z = convert (Array{eltype (y)}, y)
1526
+ @test z isa Array{eltype (y)}
1527
+ @test z == x
1528
+ z = convert (Array{eltype (y)}, view (y, 1 : 4 ))
1529
+ @test z isa Array{eltype (y)}
1530
+ @test z == x
1531
+
1532
+ x = [1 ,1 ,2 ,missing ]
1533
+ y = categorical (x)
1534
+ z = convert (Array{eltype (y)}, y)
1535
+ @test z isa Array{eltype (y)}
1536
+ @test z ≅ x
1537
+ z = convert (Array{eltype (y)}, view (y, 1 : 4 ))
1538
+ @test z isa Array{eltype (y)}
1539
+ @test z ≅ x
1540
+
1541
+ x = [1 ,1 ,2 ,2 ]
1542
+ y = categorical (x)
1543
+ z = convert (Vector{eltype (y)}, y)
1544
+ @test z isa Vector{eltype (y)}
1545
+ @test z == x
1546
+ z = convert (Vector{eltype (y)}, view (y, 1 : 4 ))
1547
+ @test z isa Vector{eltype (y)}
1548
+ @test z == x
1549
+
1550
+ x = [1 ,1 ,2 ,missing ]
1551
+ y = categorical (x)
1552
+ z = convert (Vector{eltype (y)}, y)
1553
+ @test z isa Vector{eltype (y)}
1554
+ @test z ≅ x
1555
+ z = convert (Vector{eltype (y)}, view (y, 1 : 4 ))
1556
+ @test z isa Vector{eltype (y)}
1557
+ @test z ≅ x
1558
+
1559
+ x = [1 1 2 2 ]
1560
+ y = categorical (x)
1561
+ z = convert (Matrix{eltype (y)}, y)
1562
+ @test z isa Matrix{eltype (y)}
1563
+ @test z == x
1564
+ z = convert (Matrix{eltype (y)}, view (y, :, 1 : 4 ))
1565
+ @test z isa Matrix{eltype (y)}
1566
+ @test z == x
1567
+
1568
+ x = [1 1 2 missing ]
1569
+ y = categorical (x)
1570
+ z = convert (Matrix{eltype (y)}, y)
1571
+ @test z isa Matrix{eltype (y)}
1572
+ @test z ≅ x
1573
+ z = convert (Matrix{eltype (y)}, view (y, :, 1 : 4 ))
1574
+ @test z isa Matrix{eltype (y)}
1575
+ @test z ≅ x
1576
+ end
1577
+
1465
1578
@testset " convert(AbstractArray{T}, x)" begin
1466
1579
x = [1 ,1 ,2 ,2 ]
1467
1580
y = categorical (x)
0 commit comments