@@ -1449,32 +1449,81 @@ def test_updated_astype() -> None:
1449
1449
s = pd .Series ([3 , 4 , 5 ])
1450
1450
s1 = pd .Series (True )
1451
1451
1452
+ # Boolean types
1453
+
1454
+ # Builtin bool types
1455
+ check (assert_type (s .astype (bool ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1456
+ check (assert_type (s .astype ("bool" ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1457
+ # Pandas nullable boolean types
1458
+ check (
1459
+ assert_type (s1 .astype (pd .BooleanDtype ()), "pd.Series[bool]" ),
1460
+ pd .Series ,
1461
+ np .bool_ ,
1462
+ )
1463
+ check (assert_type (s1 .astype ("boolean" ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1464
+ # Numpy bool type
1465
+ check (assert_type (s .astype (np .bool_ ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1466
+
1467
+ # Integer types
1468
+
1469
+ # Builtin integer types
1452
1470
check (assert_type (s .astype (int ), "pd.Series[int]" ), pd .Series , np .integer )
1453
1471
check (assert_type (s .astype ("int" ), "pd.Series[int]" ), pd .Series , np .integer )
1454
- check ( assert_type ( s . astype ( "int32" ), "pd.Series[int]" ), pd . Series , np . int32 )
1472
+ # Pandas nullable integer types
1455
1473
check (assert_type (s .astype (pd .Int8Dtype ()), "pd.Series[int]" ), pd .Series , np .int8 )
1456
1474
check (assert_type (s .astype (pd .Int16Dtype ()), "pd.Series[int]" ), pd .Series , np .int16 )
1457
1475
check (assert_type (s .astype (pd .Int32Dtype ()), "pd.Series[int]" ), pd .Series , np .int32 )
1458
1476
check (assert_type (s .astype (pd .Int64Dtype ()), "pd.Series[int]" ), pd .Series , np .int64 )
1477
+ check (assert_type (s .astype ("Int8" ), "pd.Series[int]" ), pd .Series , np .int8 )
1478
+ check (assert_type (s .astype ("Int16" ), "pd.Series[int]" ), pd .Series , np .int16 )
1479
+ check (assert_type (s .astype ("Int32" ), "pd.Series[int]" ), pd .Series , np .int32 )
1480
+ check (assert_type (s .astype ("Int64" ), "pd.Series[int]" ), pd .Series , np .int64 )
1481
+ # Numpy signed integer types
1482
+ check (assert_type (s .astype (np .byte ), "pd.Series[int]" ), pd .Series , np .byte )
1459
1483
check (assert_type (s .astype (np .int8 ), "pd.Series[int]" ), pd .Series , np .int8 )
1460
1484
check (assert_type (s .astype (np .int16 ), "pd.Series[int]" ), pd .Series , np .int16 )
1461
1485
check (assert_type (s .astype (np .int32 ), "pd.Series[int]" ), pd .Series , np .int32 )
1462
1486
check (assert_type (s .astype (np .int64 ), "pd.Series[int]" ), pd .Series , np .int64 )
1487
+ check (assert_type (s .astype (np .intp ), "pd.Series[int]" ), pd .Series , np .intp )
1488
+ check (assert_type (s .astype ("byte" ), "pd.Series[int]" ), pd .Series , np .byte )
1489
+ check (assert_type (s .astype ("int8" ), "pd.Series[int]" ), pd .Series , np .int8 )
1490
+ check (assert_type (s .astype ("int16" ), "pd.Series[int]" ), pd .Series , np .int16 )
1491
+ check (assert_type (s .astype ("int32" ), "pd.Series[int]" ), pd .Series , np .int32 )
1492
+ check (assert_type (s .astype ("int64" ), "pd.Series[int]" ), pd .Series , np .int64 )
1493
+ check (assert_type (s .astype ("intp" ), "pd.Series[int]" ), pd .Series , np .intp )
1494
+ # Numpy unsigned integer types
1495
+ check (assert_type (s .astype (np .ubyte ), "pd.Series[int]" ), pd .Series , np .ubyte )
1463
1496
check (assert_type (s .astype (np .uint8 ), "pd.Series[int]" ), pd .Series , np .uint8 )
1464
1497
check (assert_type (s .astype (np .uint16 ), "pd.Series[int]" ), pd .Series , np .uint16 )
1465
1498
check (assert_type (s .astype (np .uint32 ), "pd.Series[int]" ), pd .Series , np .uint32 )
1466
1499
check (assert_type (s .astype (np .uint64 ), "pd.Series[int]" ), pd .Series , np .uint64 )
1467
- check (assert_type (s .astype (np .intp ), "pd.Series[int]" ), pd .Series , np .intp )
1468
1500
check (assert_type (s .astype (np .uintp ), "pd.Series[int]" ), pd .Series , np .uintp )
1469
- check (assert_type (s .astype (np .byte ), "pd.Series[int]" ), pd .Series , np .byte )
1470
- check (assert_type (s .astype (np .ubyte ), "pd.Series[int]" ), pd .Series , np .ubyte )
1501
+ check (assert_type (s .astype ("ubyte" ), "pd.Series[int]" ), pd .Series , np .ubyte )
1502
+ check (assert_type (s .astype ("uint8" ), "pd.Series[int]" ), pd .Series , np .uint8 )
1503
+ check (assert_type (s .astype ("uint16" ), "pd.Series[int]" ), pd .Series , np .uint16 )
1504
+ check (assert_type (s .astype ("uint32" ), "pd.Series[int]" ), pd .Series , np .uint32 )
1505
+ check (assert_type (s .astype ("uint64" ), "pd.Series[int]" ), pd .Series , np .uint64 )
1506
+ check (assert_type (s .astype ("uintp" ), "pd.Series[int]" ), pd .Series , np .uintp )
1507
+
1508
+ # String types
1471
1509
1510
+ # Builtin str types
1472
1511
check (assert_type (s .astype (str ), "pd.Series[str]" ), pd .Series , str )
1473
- check (assert_type (s .astype (pd .StringDtype ()), "pd.Series[str]" ), pd .Series , str )
1474
1512
check (assert_type (s .astype ("str" ), "pd.Series[str]" ), pd .Series , str )
1513
+ # Pandas nullable string types
1514
+ check (assert_type (s .astype (pd .StringDtype ()), "pd.Series[str]" ), pd .Series , str )
1515
+ check (assert_type (s .astype ("string" ), "pd.Series[str]" ), pd .Series , str )
1516
+
1517
+ # Bytes types
1475
1518
1476
1519
check (assert_type (s .astype (bytes ), "pd.Series[bytes]" ), pd .Series , bytes )
1477
1520
1521
+ # Float types
1522
+
1523
+ # Builtin float types
1524
+ check (assert_type (s .astype (float ), "pd.Series[float]" ), pd .Series , float )
1525
+ check (assert_type (s .astype ("float" ), "pd.Series[float]" ), pd .Series , float )
1526
+ # Pandas nullable float types
1478
1527
check (
1479
1528
assert_type (s .astype (pd .Float32Dtype ()), "pd.Series[float]" ),
1480
1529
pd .Series ,
@@ -1485,12 +1534,22 @@ def test_updated_astype() -> None:
1485
1534
pd .Series ,
1486
1535
np .float64 ,
1487
1536
)
1537
+ check (assert_type (s .astype ("Float32" ), "pd.Series[float]" ), pd .Series , np .float32 )
1538
+ check (assert_type (s .astype ("Float64" ), "pd.Series[float]" ), pd .Series , np .float64 )
1539
+ # Numpy float types
1488
1540
check (assert_type (s .astype (np .float16 ), "pd.Series[float]" ), pd .Series , np .float16 )
1489
1541
check (assert_type (s .astype (np .float32 ), "pd.Series[float]" ), pd .Series , np .float32 )
1490
1542
check (assert_type (s .astype (np .float64 ), "pd.Series[float]" ), pd .Series , np .float64 )
1491
- check (assert_type (s .astype (float ), "pd.Series[float]" ), pd .Series , float )
1492
- check (assert_type (s .astype ("float" ), "pd.Series[float]" ), pd .Series , float )
1543
+ check (assert_type (s .astype ("float16" ), "pd.Series[float]" ), pd .Series , np .float16 )
1544
+ check (assert_type (s .astype ("float32" ), "pd.Series[float]" ), pd .Series , np .float32 )
1545
+ check (assert_type (s .astype ("float64" ), "pd.Series[float]" ), pd .Series , np .float64 )
1493
1546
1547
+ # Complex types
1548
+
1549
+ # Builtin complex types
1550
+ check (assert_type (s .astype (complex ), "pd.Series[complex]" ), pd .Series , complex )
1551
+ check (assert_type (s .astype ("complex" ), "pd.Series[complex]" ), pd .Series , complex )
1552
+ # Numpy complex types
1494
1553
check (
1495
1554
assert_type (s .astype (np .complex64 ), "pd.Series[complex]" ),
1496
1555
pd .Series ,
@@ -1501,17 +1560,16 @@ def test_updated_astype() -> None:
1501
1560
pd .Series ,
1502
1561
np .complex128 ,
1503
1562
)
1504
- check (assert_type (s .astype (complex ), "pd.Series[complex]" ), pd .Series , complex )
1505
- check (assert_type (s .astype ("complex" ), "pd.Series[complex]" ), pd .Series , complex )
1506
-
1507
1563
check (
1508
- assert_type (s1 .astype (pd . BooleanDtype ()) , "pd.Series[bool ]" ),
1564
+ assert_type (s .astype ("complex64" ) , "pd.Series[complex ]" ),
1509
1565
pd .Series ,
1510
- np .bool_ ,
1566
+ np .complex64 ,
1567
+ )
1568
+ check (
1569
+ assert_type (s .astype ("complex128" ), "pd.Series[complex]" ),
1570
+ pd .Series ,
1571
+ np .complex128 ,
1511
1572
)
1512
- check (assert_type (s .astype ("bool" ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1513
- check (assert_type (s .astype (bool ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1514
- check (assert_type (s .astype (np .bool_ ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1515
1573
1516
1574
check (
1517
1575
assert_type (s .astype ("timedelta64[ns]" ), TimedeltaSeries ),
0 commit comments