@@ -1577,31 +1577,32 @@ def test_string_accessors():
1577
1577
)
1578
1578
s2 = pd .Series ([["apple" , "banana" ], ["cherry" , "date" ], [1 , "eggplant" ]])
1579
1579
s3 = pd .Series (["a1" , "b2" , "c3" ])
1580
- check (assert_type (s .str .capitalize (), pd .Series ), pd .Series )
1581
- check (assert_type (s .str .casefold (), pd .Series ), pd .Series )
1580
+ s4 = pd .Series ([b"a1" , b"b2" , b"c3" ])
1581
+ check (assert_type (s .str .capitalize (), "pd.Series[str]" ), pd .Series , str )
1582
+ check (assert_type (s .str .casefold (), "pd.Series[str]" ), pd .Series , str )
1582
1583
check (assert_type (s .str .cat (sep = "X" ), str ), str )
1583
- check (assert_type (s .str .center (10 ), pd .Series ), pd .Series )
1584
+ check (assert_type (s .str .center (10 ), " pd.Series[str]" ), pd .Series , str )
1584
1585
check (assert_type (s .str .contains ("a" ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1585
1586
check (
1586
1587
assert_type (s .str .contains (re .compile (r"a" )), "pd.Series[bool]" ),
1587
1588
pd .Series ,
1588
1589
np .bool_ ,
1589
1590
)
1590
1591
check (assert_type (s .str .count ("pp" ), "pd.Series[int]" ), pd .Series , np .integer )
1591
- check (assert_type (s .str .decode ("utf-8" ), pd .Series ), pd .Series )
1592
- check (assert_type (s .str .encode ("latin-1" ), pd .Series ), pd .Series )
1592
+ check (assert_type (s4 .str .decode ("utf-8" ), " pd.Series[str]" ), pd .Series , str )
1593
+ check (assert_type (s .str .encode ("latin-1" ), " pd.Series[bytes]" ), pd .Series , bytes )
1593
1594
check (assert_type (s .str .endswith ("e" ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1594
1595
check (
1595
1596
assert_type (s .str .endswith (("e" , "f" )), "pd.Series[bool]" ), pd .Series , np .bool_
1596
1597
)
1597
1598
check (assert_type (s3 .str .extract (r"([ab])?(\d)" ), pd .DataFrame ), pd .DataFrame )
1598
1599
check (assert_type (s3 .str .extractall (r"([ab])?(\d)" ), pd .DataFrame ), pd .DataFrame )
1599
- check (assert_type (s .str .find ("p" ), pd .Series ), pd .Series )
1600
+ check (assert_type (s .str .find ("p" ), " pd.Series[int]" ), pd .Series , np . int64 )
1600
1601
check (assert_type (s .str .findall ("pp" ), "pd.Series[list[str]]" ), pd .Series , list )
1601
1602
check (assert_type (s .str .fullmatch ("apple" ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1602
- check (assert_type (s .str .get (2 ), pd .Series ), pd .Series )
1603
+ check (assert_type (s .str .get (2 ), " pd.Series[str]" ), pd .Series , str )
1603
1604
check (assert_type (s .str .get_dummies (), pd .DataFrame ), pd .DataFrame )
1604
- check (assert_type (s .str .index ("p" ), pd .Series ), pd .Series )
1605
+ check (assert_type (s .str .index ("p" ), " pd.Series[int]" ), pd .Series , np . int64 )
1605
1606
check (assert_type (s .str .isalnum (), "pd.Series[bool]" ), pd .Series , np .bool_ )
1606
1607
check (assert_type (s .str .isalpha (), "pd.Series[bool]" ), pd .Series , np .bool_ )
1607
1608
check (assert_type (s .str .isdecimal (), "pd.Series[bool]" ), pd .Series , np .bool_ )
@@ -1613,20 +1614,20 @@ def test_string_accessors():
1613
1614
check (assert_type (s .str .isupper (), "pd.Series[bool]" ), pd .Series , np .bool_ )
1614
1615
check (assert_type (s2 .str .join ("-" ), pd .Series ), pd .Series )
1615
1616
check (assert_type (s .str .len (), "pd.Series[int]" ), pd .Series , np .integer )
1616
- check (assert_type (s .str .ljust (80 ), pd .Series ), pd .Series )
1617
- check (assert_type (s .str .lower (), pd .Series ), pd .Series )
1618
- check (assert_type (s .str .lstrip ("a" ), pd .Series ), pd .Series )
1617
+ check (assert_type (s .str .ljust (80 ), " pd.Series[str]" ), pd .Series , str )
1618
+ check (assert_type (s .str .lower (), " pd.Series[str]" ), pd .Series , str )
1619
+ check (assert_type (s .str .lstrip ("a" ), " pd.Series[str]" ), pd .Series , str )
1619
1620
check (assert_type (s .str .match ("pp" ), "pd.Series[bool]" ), pd .Series , np .bool_ )
1620
- check (assert_type (s .str .normalize ("NFD" ), pd .Series ), pd .Series )
1621
- check (assert_type (s .str .pad (80 , "right" ), pd .Series ), pd .Series )
1621
+ check (assert_type (s .str .normalize ("NFD" ), " pd.Series[str]" ), pd .Series , str )
1622
+ check (assert_type (s .str .pad (80 , "right" ), " pd.Series[str]" ), pd .Series , str )
1622
1623
check (assert_type (s .str .partition ("p" ), pd .DataFrame ), pd .DataFrame )
1623
- check (assert_type (s .str .removeprefix ("a" ), pd .Series ), pd .Series )
1624
- check (assert_type (s .str .removesuffix ("e" ), pd .Series ), pd .Series )
1625
- check (assert_type (s .str .repeat (2 ), pd .Series ), pd .Series )
1626
- check (assert_type (s .str .replace ("a" , "X" ), pd .Series ), pd .Series )
1627
- check (assert_type (s .str .rfind ("e" ), pd .Series ), pd .Series )
1628
- check (assert_type (s .str .rindex ("p" ), pd .Series ), pd .Series )
1629
- check (assert_type (s .str .rjust (80 ), pd .Series ), pd .Series )
1624
+ check (assert_type (s .str .removeprefix ("a" ), " pd.Series[str]" ), pd .Series , str )
1625
+ check (assert_type (s .str .removesuffix ("e" ), " pd.Series[str]" ), pd .Series , str )
1626
+ check (assert_type (s .str .repeat (2 ), " pd.Series[str]" ), pd .Series , str )
1627
+ check (assert_type (s .str .replace ("a" , "X" ), " pd.Series[str]" ), pd .Series , str )
1628
+ check (assert_type (s .str .rfind ("e" ), " pd.Series[int]" ), pd .Series , np . int64 )
1629
+ check (assert_type (s .str .rindex ("p" ), " pd.Series[int]" ), pd .Series , np . int64 )
1630
+ check (assert_type (s .str .rjust (80 ), " pd.Series[str]" ), pd .Series , str )
1630
1631
check (assert_type (s .str .rpartition ("p" ), pd .DataFrame ), pd .DataFrame )
1631
1632
check (assert_type (s .str .rsplit ("a" ), "pd.Series[list[str]]" ), pd .Series , list )
1632
1633
check (assert_type (s .str .rsplit ("a" , expand = True ), pd .DataFrame ), pd .DataFrame )
@@ -1635,9 +1636,11 @@ def test_string_accessors():
1635
1636
pd .Series ,
1636
1637
list ,
1637
1638
)
1638
- check (assert_type (s .str .rstrip (), pd .Series ), pd .Series )
1639
- check (assert_type (s .str .slice (0 , 4 , 2 ), pd .Series ), pd .Series )
1640
- check (assert_type (s .str .slice_replace (0 , 2 , "XX" ), pd .Series ), pd .Series )
1639
+ check (assert_type (s .str .rstrip (), "pd.Series[str]" ), pd .Series , str )
1640
+ check (assert_type (s .str .slice (0 , 4 , 2 ), "pd.Series[str]" ), pd .Series , str )
1641
+ check (
1642
+ assert_type (s .str .slice_replace (0 , 2 , "XX" ), "pd.Series[str]" ), pd .Series , str
1643
+ )
1641
1644
check (assert_type (s .str .split ("a" ), "pd.Series[list[str]]" ), pd .Series , list )
1642
1645
# GH 194
1643
1646
check (assert_type (s .str .split ("a" , expand = True ), pd .DataFrame ), pd .DataFrame )
@@ -1652,13 +1655,19 @@ def test_string_accessors():
1652
1655
pd .Series ,
1653
1656
np .bool_ ,
1654
1657
)
1655
- check (assert_type (s .str .strip (), pd .Series ), pd .Series )
1656
- check (assert_type (s .str .swapcase (), pd .Series ), pd .Series )
1657
- check (assert_type (s .str .title (), pd .Series ), pd .Series )
1658
- check (assert_type (s .str .translate (None ), pd .Series ), pd .Series )
1659
- check (assert_type (s .str .upper (), pd .Series ), pd .Series )
1660
- check (assert_type (s .str .wrap (80 ), pd .Series ), pd .Series )
1661
- check (assert_type (s .str .zfill (10 ), pd .Series ), pd .Series )
1658
+ check (assert_type (s .str .strip (), "pd.Series[str]" ), pd .Series , str )
1659
+ check (assert_type (s .str .swapcase (), "pd.Series[str]" ), pd .Series , str )
1660
+ check (assert_type (s .str .title (), "pd.Series[str]" ), pd .Series , str )
1661
+ check (
1662
+ assert_type (
1663
+ s .str .translate (str .maketrans ({"ñ" : "n" , "ç" : "c" })), "pd.Series[str]"
1664
+ ),
1665
+ pd .Series ,
1666
+ str ,
1667
+ )
1668
+ check (assert_type (s .str .upper (), "pd.Series[str]" ), pd .Series , str )
1669
+ check (assert_type (s .str .wrap (80 ), "pd.Series[str]" ), pd .Series , str )
1670
+ check (assert_type (s .str .zfill (10 ), "pd.Series[str]" ), pd .Series , str )
1662
1671
1663
1672
1664
1673
def test_series_overloads_cat ():
@@ -1669,22 +1678,22 @@ def test_series_overloads_cat():
1669
1678
check (assert_type (s .str .cat (None , sep = ";" ), str ), str )
1670
1679
check (
1671
1680
assert_type (
1672
- s .str .cat (["A" , "B" , "C" , "D" , "E" , "F" , "G" ], sep = ";" ), UnknownSeries
1681
+ s .str .cat (["A" , "B" , "C" , "D" , "E" , "F" , "G" ], sep = ";" ),
1682
+ "pd.Series[str]" ,
1673
1683
),
1674
- UnknownSeries ,
1684
+ pd .Series ,
1685
+ str ,
1675
1686
)
1676
1687
check (
1677
1688
assert_type (
1678
1689
s .str .cat (pd .Series (["A" , "B" , "C" , "D" , "E" , "F" , "G" ]), sep = ";" ),
1679
- UnknownSeries ,
1690
+ "pd.Series[str]" ,
1680
1691
),
1681
- UnknownSeries ,
1692
+ pd .Series ,
1693
+ str ,
1682
1694
)
1683
1695
unknown_s : UnknownSeries = pd .DataFrame ({"a" : ["a" , "b" ]})["a" ]
1684
- check (
1685
- assert_type (s .str .cat (unknown_s , sep = ";" ), UnknownSeries ),
1686
- UnknownSeries ,
1687
- )
1696
+ check (assert_type (s .str .cat (unknown_s , sep = ";" ), "pd.Series[str]" ), pd .Series , str )
1688
1697
1689
1698
1690
1699
def test_series_overloads_partition ():
@@ -1703,13 +1712,21 @@ def test_series_overloads_partition():
1703
1712
check (
1704
1713
assert_type (s .str .partition (sep = ";" , expand = True ), pd .DataFrame ), pd .DataFrame
1705
1714
)
1706
- check (assert_type (s .str .partition (sep = ";" , expand = False ), pd .Series ), pd .Series )
1715
+ check (
1716
+ assert_type (s .str .partition (sep = ";" , expand = False ), "pd.Series[type[object]]" ),
1717
+ pd .Series ,
1718
+ object ,
1719
+ )
1707
1720
1708
1721
check (assert_type (s .str .rpartition (sep = ";" ), pd .DataFrame ), pd .DataFrame )
1709
1722
check (
1710
1723
assert_type (s .str .rpartition (sep = ";" , expand = True ), pd .DataFrame ), pd .DataFrame
1711
1724
)
1712
- check (assert_type (s .str .rpartition (sep = ";" , expand = False ), pd .Series ), pd .Series )
1725
+ check (
1726
+ assert_type (s .str .rpartition (sep = ";" , expand = False ), "pd.Series[type[object]]" ),
1727
+ pd .Series ,
1728
+ object ,
1729
+ )
1713
1730
1714
1731
1715
1732
def test_series_overloads_extract ():
@@ -1720,10 +1737,19 @@ def test_series_overloads_extract():
1720
1737
check (
1721
1738
assert_type (s .str .extract (r"[ab](\d)" , expand = True ), pd .DataFrame ), pd .DataFrame
1722
1739
)
1723
- check (assert_type (s .str .extract (r"[ab](\d)" , expand = False ), pd .Series ), pd .Series )
1724
1740
check (
1725
- assert_type (s .str .extract (r"[ab](\d)" , re .IGNORECASE , False ), pd .Series ),
1741
+ assert_type (
1742
+ s .str .extract (r"[ab](\d)" , expand = False ), "pd.Series[type[object]]"
1743
+ ),
1726
1744
pd .Series ,
1745
+ object ,
1746
+ )
1747
+ check (
1748
+ assert_type (
1749
+ s .str .extract (r"[ab](\d)" , re .IGNORECASE , False ), "pd.Series[type[object]]"
1750
+ ),
1751
+ pd .Series ,
1752
+ object ,
1727
1753
)
1728
1754
1729
1755
0 commit comments