@@ -939,7 +939,33 @@ def str_find(arr, sub, start=0, end=None, side='left'):
939
939
940
940
return _na_map (f , arr , dtype = int )
941
941
942
+ _shared_docs ['index' ] = textwrap .dedent ("""
943
+ Return %(side)s indexes in each strings where the substring is
944
+ fully contained between [start:end]. This is the same as
945
+ ``str.%(similar)s`` except instead of returning -1, it raises a ValueError
946
+ when the substring is not found. Equivalent to standard ``str.%(method)s``.
942
947
948
+ Parameters
949
+ ----------
950
+ sub : str
951
+ Substring being searched
952
+ start : int
953
+ Left edge index
954
+ end : int
955
+ Right edge index
956
+
957
+ Returns
958
+ -------
959
+ found : Series/Index of objects
960
+
961
+ See Also
962
+ --------
963
+ %(also)s
964
+ """ )
965
+
966
+ @Appender (_shared_docs ['index' ] %
967
+ dict (side = 'lowest' , similar = 'find' , method = 'index' ,
968
+ also = 'rindex : Return highest indexes in each strings' ))
943
969
def str_index (arr , sub , start = 0 , end = None , side = 'left' ):
944
970
if not isinstance (sub , compat .string_types ):
945
971
msg = 'expected a string object, not {0}'
@@ -1125,6 +1151,18 @@ def f(x):
1125
1151
return _na_map (f , arr )
1126
1152
1127
1153
1154
+ _shared_docs ['str_strip' ] = textwrap .dedent ("""
1155
+ Strip whitespace (including newlines) from each string in the
1156
+ Series/Index from %(side)s. Equivalent to :meth:`str.%(method)s`.
1157
+
1158
+ Returns
1159
+ -------
1160
+ stripped : Series/Index of objects
1161
+ """ )
1162
+
1163
+
1164
+ @Appender (_shared_docs ['str_strip' ] % dict (side = 'left and right sides' ,
1165
+ method = 'strip' ))
1128
1166
def str_strip (arr , to_strip = None , side = 'both' ):
1129
1167
"""
1130
1168
Strip whitespace (including newlines) from each string in the
@@ -1317,6 +1355,27 @@ def str_encode(arr, encoding, errors="strict"):
1317
1355
return _na_map (f , arr )
1318
1356
1319
1357
1358
+ def str_normalize (arr , form ):
1359
+ """
1360
+ Return the Unicode normal form for the strings in the Series/Index.
1361
+ For more information on the forms, see the
1362
+ :func:`unicodedata.normalize`.
1363
+
1364
+ Parameters
1365
+ ----------
1366
+ form : {'NFC', 'NFKC', 'NFD', 'NFKD'}
1367
+ Unicode form
1368
+
1369
+ Returns
1370
+ -------
1371
+ normalized : Series/Index of objects
1372
+ """
1373
+ import unicodedata
1374
+ f = lambda x : unicodedata .normalize (form , compat .u_safe (x ))
1375
+ result = _na_map (f , arr )
1376
+ return result
1377
+
1378
+
1320
1379
def _noarg_wrapper (f , docstring = None , ** kargs ):
1321
1380
def wrapper (self ):
1322
1381
result = _na_map (f , self ._data , ** kargs )
@@ -1353,7 +1412,7 @@ def wrapper3(self, pat, na=np.nan):
1353
1412
return wrapper
1354
1413
1355
1414
1356
- def copy (source ):
1415
+ def copy_doc (source ):
1357
1416
"Copy a docstring from another source function (if present)"
1358
1417
1359
1418
def do_copy (target ):
@@ -1466,18 +1525,18 @@ def cons_row(x):
1466
1525
cons = self ._orig ._constructor
1467
1526
return cons (result , name = name , index = index )
1468
1527
1469
- @copy (str_cat )
1528
+ @copy_doc (str_cat )
1470
1529
def cat (self , others = None , sep = None , na_rep = None ):
1471
1530
data = self ._orig if self ._is_categorical else self ._data
1472
1531
result = str_cat (data , others = others , sep = sep , na_rep = na_rep )
1473
1532
return self ._wrap_result (result , use_codes = (not self ._is_categorical ))
1474
1533
1475
- @copy (str_split )
1534
+ @copy_doc (str_split )
1476
1535
def split (self , pat = None , n = - 1 , expand = False ):
1477
1536
result = str_split (self ._data , pat , n = n )
1478
1537
return self ._wrap_result (result , expand = expand )
1479
1538
1480
- @copy (str_rsplit )
1539
+ @copy_doc (str_rsplit )
1481
1540
def rsplit (self , pat = None , n = - 1 , expand = False ):
1482
1541
result = str_rsplit (self ._data , pat , n = n )
1483
1542
return self ._wrap_result (result , expand = expand )
@@ -1548,40 +1607,40 @@ def rpartition(self, pat=' ', expand=True):
1548
1607
result = _na_map (f , self ._data )
1549
1608
return self ._wrap_result (result , expand = expand )
1550
1609
1551
- @copy (str_get )
1610
+ @copy_doc (str_get )
1552
1611
def get (self , i ):
1553
1612
result = str_get (self ._data , i )
1554
1613
return self ._wrap_result (result )
1555
1614
1556
- @copy (str_join )
1615
+ @copy_doc (str_join )
1557
1616
def join (self , sep ):
1558
1617
result = str_join (self ._data , sep )
1559
1618
return self ._wrap_result (result )
1560
1619
1561
- @copy (str_contains )
1620
+ @copy_doc (str_contains )
1562
1621
def contains (self , pat , case = True , flags = 0 , na = np .nan , regex = True ):
1563
1622
result = str_contains (self ._data , pat , case = case , flags = flags , na = na ,
1564
1623
regex = regex )
1565
1624
return self ._wrap_result (result )
1566
1625
1567
- @copy (str_match )
1626
+ @copy_doc (str_match )
1568
1627
def match (self , pat , case = True , flags = 0 , na = np .nan , as_indexer = None ):
1569
1628
result = str_match (self ._data , pat , case = case , flags = flags , na = na ,
1570
1629
as_indexer = as_indexer )
1571
1630
return self ._wrap_result (result )
1572
1631
1573
- @copy (str_replace )
1632
+ @copy_doc (str_replace )
1574
1633
def replace (self , pat , repl , n = - 1 , case = None , flags = 0 ):
1575
1634
result = str_replace (self ._data , pat , repl , n = n , case = case ,
1576
1635
flags = flags )
1577
1636
return self ._wrap_result (result )
1578
1637
1579
- @copy (str_repeat )
1638
+ @copy_doc (str_repeat )
1580
1639
def repeat (self , repeats ):
1581
1640
result = str_repeat (self ._data , repeats )
1582
1641
return self ._wrap_result (result )
1583
1642
1584
- @copy (str_pad )
1643
+ @copy_doc (str_pad )
1585
1644
def pad (self , width , side = 'left' , fillchar = ' ' ):
1586
1645
result = str_pad (self ._data , width , side = side , fillchar = fillchar )
1587
1646
return self ._wrap_result (result )
@@ -1634,37 +1693,27 @@ def zfill(self, width):
1634
1693
result = str_pad (self ._data , width , side = 'left' , fillchar = '0' )
1635
1694
return self ._wrap_result (result )
1636
1695
1637
- @copy (str_slice )
1696
+ @copy_doc (str_slice )
1638
1697
def slice (self , start = None , stop = None , step = None ):
1639
1698
result = str_slice (self ._data , start , stop , step )
1640
1699
return self ._wrap_result (result )
1641
1700
1642
- @copy (str_slice_replace )
1701
+ @copy_doc (str_slice_replace )
1643
1702
def slice_replace (self , start = None , stop = None , repl = None ):
1644
1703
result = str_slice_replace (self ._data , start , stop , repl )
1645
1704
return self ._wrap_result (result )
1646
1705
1647
- @copy (str_decode )
1706
+ @copy_doc (str_decode )
1648
1707
def decode (self , encoding , errors = "strict" ):
1649
1708
result = str_decode (self ._data , encoding , errors )
1650
1709
return self ._wrap_result (result )
1651
1710
1652
- @copy (str_encode )
1711
+ @copy_doc (str_encode )
1653
1712
def encode (self , encoding , errors = "strict" ):
1654
1713
result = str_encode (self ._data , encoding , errors )
1655
1714
return self ._wrap_result (result )
1656
1715
1657
- _shared_docs ['str_strip' ] = ("""
1658
- Strip whitespace (including newlines) from each string in the
1659
- Series/Index from %(side)s. Equivalent to :meth:`str.%(method)s`.
1660
-
1661
- Returns
1662
- -------
1663
- stripped : Series/Index of objects
1664
- """ )
1665
-
1666
- @Appender (_shared_docs ['str_strip' ] % dict (side = 'left and right sides' ,
1667
- method = 'strip' ))
1716
+ @copy_doc (str_strip )
1668
1717
def strip (self , to_strip = None ):
1669
1718
result = str_strip (self ._data , to_strip , side = 'both' )
1670
1719
return self ._wrap_result (result )
@@ -1681,12 +1730,12 @@ def rstrip(self, to_strip=None):
1681
1730
result = str_strip (self ._data , to_strip , side = 'right' )
1682
1731
return self ._wrap_result (result )
1683
1732
1684
- @copy (str_wrap )
1733
+ @copy_doc (str_wrap )
1685
1734
def wrap (self , width , ** kwargs ):
1686
1735
result = str_wrap (self ._data , width , ** kwargs )
1687
1736
return self ._wrap_result (result )
1688
1737
1689
- @copy (str_get_dummies )
1738
+ @copy_doc (str_get_dummies )
1690
1739
def get_dummies (self , sep = '|' ):
1691
1740
# we need to cast to Series of strings as only that has all
1692
1741
# methods available for making the dummies...
@@ -1695,7 +1744,7 @@ def get_dummies(self, sep='|'):
1695
1744
return self ._wrap_result (result , use_codes = (not self ._is_categorical ),
1696
1745
name = name , expand = True )
1697
1746
1698
- @copy (str_translate )
1747
+ @copy_doc (str_translate )
1699
1748
def translate (self , table , deletechars = None ):
1700
1749
result = str_translate (self ._data , table , deletechars )
1701
1750
return self ._wrap_result (result )
@@ -1705,11 +1754,11 @@ def translate(self, table, deletechars=None):
1705
1754
endswith = _pat_wrapper (str_endswith , na = True )
1706
1755
findall = _pat_wrapper (str_findall , flags = True )
1707
1756
1708
- @copy (str_extract )
1757
+ @copy_doc (str_extract )
1709
1758
def extract (self , pat , flags = 0 , expand = None ):
1710
1759
return str_extract (self , pat , flags = flags , expand = expand )
1711
1760
1712
- @copy (str_extractall )
1761
+ @copy_doc (str_extractall )
1713
1762
def extractall (self , pat , flags = 0 ):
1714
1763
return str_extractall (self ._orig , pat , flags = flags )
1715
1764
@@ -1750,52 +1799,12 @@ def rfind(self, sub, start=0, end=None):
1750
1799
result = str_find (self ._data , sub , start = start , end = end , side = 'right' )
1751
1800
return self ._wrap_result (result )
1752
1801
1802
+ @copy_doc (str_normalize )
1753
1803
def normalize (self , form ):
1754
- """Return the Unicode normal form for the strings in the Series/Index.
1755
- For more information on the forms, see the
1756
- :func:`unicodedata.normalize`.
1757
-
1758
- Parameters
1759
- ----------
1760
- form : {'NFC', 'NFKC', 'NFD', 'NFKD'}
1761
- Unicode form
1762
-
1763
- Returns
1764
- -------
1765
- normalized : Series/Index of objects
1766
- """
1767
- import unicodedata
1768
- f = lambda x : unicodedata .normalize (form , compat .u_safe (x ))
1769
- result = _na_map (f , self ._data )
1804
+ result = str_normalize (self ._data , form )
1770
1805
return self ._wrap_result (result )
1771
1806
1772
- _shared_docs ['index' ] = ("""
1773
- Return %(side)s indexes in each strings where the substring is
1774
- fully contained between [start:end]. This is the same as
1775
- ``str.%(similar)s`` except instead of returning -1, it raises a ValueError
1776
- when the substring is not found. Equivalent to standard ``str.%(method)s``.
1777
-
1778
- Parameters
1779
- ----------
1780
- sub : str
1781
- Substring being searched
1782
- start : int
1783
- Left edge index
1784
- end : int
1785
- Right edge index
1786
-
1787
- Returns
1788
- -------
1789
- found : Series/Index of objects
1790
-
1791
- See Also
1792
- --------
1793
- %(also)s
1794
- """ )
1795
-
1796
- @Appender (_shared_docs ['index' ] %
1797
- dict (side = 'lowest' , similar = 'find' , method = 'index' ,
1798
- also = 'rindex : Return highest indexes in each strings' ))
1807
+ @copy_doc (str_index )
1799
1808
def index (self , sub , start = 0 , end = None ):
1800
1809
result = str_index (self ._data , sub , start = start , end = end , side = 'left' )
1801
1810
return self ._wrap_result (result )
0 commit comments